Example #1
0
        /// <summary>
        /// Lookup the exchange rate between two currencies at a given
        /// date.  If the given type is Direct, only direct exchange
        /// rates will be returned if available; if Derived, direct
        /// rates are still preferred but derived rates are allowed.
        /// </summary>
        /// <remarks>
        /// if two or more exchange-rate chains are possible
        /// which allow to specify a requested rate, it is
        /// unspecified which one is returned.
        /// </remarks>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <param name="date"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public ExchangeRate lookup(Currency source, Currency target, Date date, ExchangeRate.Type type)
        {
            if (source == target)
            {
                return(new ExchangeRate(source, target, 1.0));
            }

            if (date == new Date())
            {
                date = Settings.evaluationDate();
            }

            if (type == ExchangeRate.Type.Direct)
            {
                return(DirectLookup(source, target, date));
            }

            if (!source.triangulationCurrency.IsEmpty)
            {
                Currency link = source.triangulationCurrency;
                return(link == target?DirectLookup(source, link, date) : ExchangeRate.chain(DirectLookup(source, link, date), lookup(link, target, date)));
            }

            if (!target.triangulationCurrency.IsEmpty)
            {
                Currency link = target.triangulationCurrency;
                return(source == link?DirectLookup(link, target, date) : ExchangeRate.chain(lookup(source, link, date), DirectLookup(link, target, date)));
            }

            return(SmartLookup(source, target, date));
        }
 public ExchangeRate.Type type()
 {
     ExchangeRate.Type ret = (ExchangeRate.Type)NQuantLibcPINVOKE.ExchangeRate_type(swigCPtr);
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
     return(ret);
 }
Example #3
0
        public ExchangeRate lookup(Currency source, Currency target, Date date, ExchangeRate.Type type)
        {
            ExchangeRate ret = new ExchangeRate(NQuantLibcPINVOKE.ExchangeRateManager_lookup__SWIG_0(swigCPtr, Currency.getCPtr(source), Currency.getCPtr(target), Date.getCPtr(date), (int)type), true);

            if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
            {
                throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
            }
            return(ret);
        }
        /// <summary>
        /// Lookup the exchange rate between two currencies at a given
        /// date.  If the given type is Direct, only direct exchange
        /// rates will be returned if available; if Derived, direct
        /// rates are still preferred but derived rates are allowed.
        /// </summary>
        /// <remarks>
        /// if two or more exchange-rate chains are possible
        /// which allow to specify a requested rate, it is
        /// unspecified which one is returned.
        /// </remarks>
        /// <param name="source"></param>
        /// <param name="target"></param>
        /// <param name="date"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public ExchangeRate lookup(Currency source, Currency target, Date date, ExchangeRate.Type type)
        {
            if (source == target)
            {
                return(new ExchangeRate(source, target, 1.0));
            }

            if (date == new Date())
            {
                date = Settings.evaluationDate();
            }

            if (type == ExchangeRate.Type.Direct)
            {
                return(directLookup(source, target, date));
            }
            else if (!source.triangulationCurrency.empty())
            {
                Currency link = source.triangulationCurrency;
                if (link == target)
                {
                    return(directLookup(source, link, date));
                }
                else
                {
                    return(ExchangeRate.chain(directLookup(source, link, date), lookup(link, target, date)));
                }
            }
            else if (!target.triangulationCurrency.empty())
            {
                Currency link = target.triangulationCurrency;
                if (source == link)
                {
                    return(directLookup(link, target, date));
                }
                else
                {
                    return(ExchangeRate.chain(lookup(source, link, date), directLookup(link, target, date)));
                }
            }
            else
            {
                return(smartLookup(source, target, date));
            }
        }