示例#1
0
        protected override void Initialize()
        {
            _usdxIndex = new Index 
            {
                Name = "USDX",
                Multiplier = 50.14348112,
                Constituents = new List<Constituent> 
                {
                    //wieght is negative when USD is not the base currency (EURUSD and GBPUSD)

                    new Constituent("EURUSD", -0.576),
                    new Constituent("USDJPY", 0.136),
                    new Constituent("GBPUSD", -0.119),
                    new Constituent("USDCAD", 0.091),
                    new Constituent("USDSEK", 0.042),
                    new Constituent("USDCHF", 0.036)
                }
            };

            _eurxIndex = new Index 
            {
                Name = "EURX",
                Multiplier = 34.38805726,
                Constituents = new List<Constituent> 
                {
                    new Constituent("EURUSD", 0.3155),
                    new Constituent("EURJPY", 0.1891),
                    new Constituent("EURGBP", 0.3056),
                    new Constituent("EURSEK", 0.0785),
                    new Constituent("EURCHF", 0.1113)
                }
            };
        }
示例#2
0
        private double CalculateIndex(Index index, DateTime date)
        {
            //index is calculated as a weighted geometric mean of its constituents' close prices

            double result = index.Multiplier;

            foreach (var weight in index.Constituents)
            {
                var series = MarketData.GetSeries(weight.Symbol, TimeFrame);
                if (series == null)
                {
                    return double.NaN;
                }
                double close = GetCloseByDate(date, series);
                result *= Math.Pow(close, weight.Weight);
            }
            return result;
        }