Exemplo n.º 1
0
        public object Clone()
        {
            PortfolioRawItem p = new PortfolioRawItem();

            p.Equity.AddRange(this.Equity);
            p.Margin.AddRange(this.Margin);
            p.StrategyParameter = this.StrategyParameter;

            return(p);
        }
Exemplo n.º 2
0
        public PortfolioRawData(SortedDictionary <string, Tuple <StrategyParameter, double[], double[]> > dictEquityAndMargin)
        {
            // calculate common length
            int length = int.MaxValue;

            foreach (var element in dictEquityAndMargin)
            {
                length = Math.Min(element.Value.Item2.Length, length);
            }
            // create two-dimensions array
            int count = dictEquityAndMargin.Count;

            double[,] rawEquity = new double[count, length];
            double[,] rawMargin = new double[count, length];

            var it = dictEquityAndMargin.GetEnumerator();

            for (int row = 0; it.MoveNext(); ++row)
            {
                double[] sourceEquity = it.Current.Value.Item2;
                double[] sourceMargin = it.Current.Value.Item3;
                for (int column = 0; column < length; ++column)
                {
                    rawEquity[row, column] = sourceEquity[column];
                    rawMargin[row, column] = sourceMargin[column];
                }
            }

            IEnumerable <string>            symbols = dictEquityAndMargin.Select(s => s.Key);
            IEnumerable <StrategyParameter> sParams = dictEquityAndMargin.Select(s => s.Value.Item1);

            double[,] equity = rawEquity;
            double[,] margin = rawMargin;

            for (int i = 0; i < equity.GetLength(0); i++)
            {
                PortfolioRawItem pri = new PortfolioRawItem();
                pri.Symbol            = symbols.ElementAt(i);
                pri.StrategyParameter = sParams.ElementAt(i);

                for (int j = 0; j < equity.GetLength(1); j++)
                {
                    pri.Equity.Add(equity[i, j]);
                    pri.Margin.Add(margin[i, j]);
                }
                portfolioRawItems.Add(pri);
            }
        }
Exemplo n.º 3
0
        public void AddInversePortfolioRawItem()
        {
            List <PortfolioRawItem> newListItems = new List <PortfolioRawItem>();

            foreach (PortfolioRawItem currPortfolioRawItem in portfolioRawItems)
            {
                PortfolioRawItem newItem    = currPortfolioRawItem.Clone() as PortfolioRawItem;
                double           baseEquity = currPortfolioRawItem.Equity[0];
                for (int i = 0; i < currPortfolioRawItem.Equity.Count; i++)
                {
                    newItem.Equity[i] = 2 * baseEquity - currPortfolioRawItem.Equity[i];
                }
                newItem.Symbol = currPortfolioRawItem.Symbol + "Inverse";

                newListItems.Add(newItem);
            }
            portfolioRawItems.AddRange(newListItems);
        }