コード例 #1
0
        /// <summary>
        /// Function: Convert a value from the Sell currency denomination to the Buy currency denomination on a given date.
        /// </summary>
        /// <param name="value">Value to be converted.
        /// </param>
        /// <param name="date">Reference date.
        /// </param>
        /// <param name="type">Time series type of time series point.
        /// </param>
        /// <param name="provider">Provider of reference time series object (Standard is AQI).
        /// </param>
        /// <param name="timeSeriesRoll">Roll type of reference time series object.
        /// </param>
        /// <param name="buy">Target currency in the conversion.
        /// </param>
        /// <param name="sell">Initial currency in the conversion.
        /// </param>
        public static double Convert(double value, DateTime date, TimeSeriesType type, DataProvider provider, TimeSeriesRollType timeSeriesRoll, Currency buy, Currency sell)
        {
            if (buy == sell)
            {
                return(value);
            }

            CurrencyPair pair = CurrencyPair.FindCurrencyPair(buy, sell);


            if (pair != null)
            {
                return(pair.Convert(value, date, type, provider, timeSeriesRoll));
            }

            CurrencyPair pair_inv = CurrencyPair.FindCurrencyPair(sell, buy);

            if (pair_inv != null)
            {
                return(pair_inv.ConvertInverse(value, date, type, provider, timeSeriesRoll));
            }

            Console.WriteLine("WARNING: NO CURRENCY PAIR FOUND - " + buy.Name + "/" + sell.Name);
            return(value);
        }
コード例 #2
0
        /// <summary>
        /// Function: Convert a value from the Sell currency denomination to the Buy currency denomination on a given date.
        /// The conversion is dependent on the definition of the FX Instrument.
        /// </summary>
        /// <param name="value">Value to be converted.
        /// </param>
        /// <param name="date">Reference date.
        /// </param>
        /// <param name="type">Time series type of time series point.
        /// </param>
        /// <param name="provider">Provider of reference time series object (Standard is AQI).
        /// </param>
        /// <param name="timeSeriesRoll">Roll type of reference time series object.
        /// </param>
        public double Convert(double value, DateTime date, TimeSeriesType type, DataProvider provider, TimeSeriesRollType timeSeriesRoll)
        {
            double fxi = FXInstrument[date, type, provider, timeSeriesRoll];

            if (double.IsNaN(fxi))
            {
                CurrencyPair pair_inv = CurrencyPair.FindCurrencyPair(CurrencySell, CurrencyBuy);

                if (pair_inv != null)
                {
                    return(pair_inv.ConvertInverse(value, date, type, provider, timeSeriesRoll));
                }

                return(value);
            }

            return(value * fxi);
        }
コード例 #3
0
ファイル: Currency.cs プロジェクト: xyicheng/QuantApp
        /// <summary>
        /// Function: Convert a value from the Sell currency denomination to the Buy currency denomination on a given date.
        /// </summary>
        /// <param name="value">Value to be converted.
        /// </param>
        /// <param name="date">Reference date.
        /// </param>
        /// <param name="type">Time series type of time series point.
        /// </param>
        /// <param name="provider">Provider of reference time series object (Standard is AQI).
        /// </param>
        /// <param name="timeSeriesRoll">Roll type of reference time series object.
        /// </param>
        /// <param name="buy">Target currency in the conversion.
        /// </param>
        /// <param name="sell">Initial currency in the conversion.
        /// </param>
        public static double Convert(double value, DateTime date, TimeSeriesType type, DataProvider provider, TimeSeriesRollType timeSeriesRoll, Currency buy, Currency sell)
        {
            if (buy == sell)
            {
                return(value);
            }

            CurrencyPair pair = CurrencyPair.FindCurrencyPair(buy, sell);

            if (pair != null)
            {
                return(pair.Convert(value, date, type, provider, timeSeriesRoll));
            }

            CurrencyPair pair_inv = CurrencyPair.FindCurrencyPair(sell, buy);

            if (pair_inv != null)
            {
                return(pair_inv.ConvertInverse(value, date, type, provider, timeSeriesRoll));
            }

            return(0.0);
        }