Exemple #1
0
        private double SimulatePerformance()
        {
            DataContainer dcPerformance    = new DataContainer();
            DataContainer dcInvestmentRate = new DataContainer();

            Depot depot = m_TradeRule.RuleEngineInfo.Depot;

            depot.Clear();
            depot.Cash = 100000;
            m_TradeRule.Prepare();
            m_TradeRule.RuleEngineInfo.Today = m_TradeRule.RuleEngineInfo.FromDate;

            while (m_TradeRule.RuleEngineInfo.Today <= m_TradeRule.RuleEngineInfo.ToDate)
            {
                UpdateDepotPositions();
                m_TradeRule.Ranking();
                m_TradeRule.SellRule();
                m_TradeRule.BuyRule();

                dcPerformance[m_TradeRule.RuleEngineInfo.Today]    = depot.Performance;
                dcInvestmentRate[m_TradeRule.RuleEngineInfo.Today] = 100.0 * depot.Asset / depot.Equity;

                System.Console.Write("Performance on {0} is {1}            \r", m_TradeRule.RuleEngineInfo.Today, depot.Performance);

                m_TradeRule.StepDate();
            }

            System.Console.WriteLine();
            m_TradeRule.Result();

            Chart chart = new Chart();

            chart.Width        = 1500;
            chart.Height       = 900;
            chart.SubSectionsX = 8;
            chart.Title        = dcPerformance.OldestDate.ToString() + " - " + dcPerformance.YoungestDate.ToString();
            chart.LabelY       = "Performance (%)";
            chart.Add(dcPerformance, Chart.LineType.Olive, "Performance");
            chart.Create(World.GetInstance().ResultPath + "performance.png");

            chart.Clear();
            chart.Title  = dcInvestmentRate.OldestDate.ToString() + " - " + dcInvestmentRate.YoungestDate.ToString();
            chart.LabelY = "Investment (%)";
            chart.Add(dcInvestmentRate, Chart.LineType.Olive, "Investment");
            chart.Create(World.GetInstance().ResultPath + "investment.png");

            return(depot.Performance);
        }