Ejemplo n.º 1
0
        private static void DoMainBackTest()
        {
            var eventBus         = new QueuedEventBus();
            var dataSource       = CsvDataSource.CreateFromFiles("Data\\Min1", new[] { Symbols.Sber, Symbols.Vtbr });
            var marketData       = new ComposedMarketData(dataSource.Bars);
            var bars             = new HistoricDataHandler(eventBus, marketData);
            var strategy         = new BuyAndHoldStrategy(eventBus, bars);
            var executionHandler = new SimulatedExecutionHandler(eventBus, bars);
            var portfolio        = new NaivePortfolio(eventBus, bars, 10000m);
            var backTest         = new BackTest(eventBus, bars, strategy, portfolio, executionHandler);

            backTest.SimulateTrading();
        }
        public void CanGetLastBarFromCsvMarketData()
        {
            var dataSource = CsvDataSource.CreateFormStrings(Mother.GenericCsvData);
            var marketData = new ComposedMarketData(dataSource.Bars);
            var eventBus   = new QueuedEventBus();

            var handler = new HistoricDataHandler(eventBus, marketData);

            Console.WriteLine("Total rows = {0}", marketData.RowKeys.Count);

            var i = 0;

            while (handler.ContinueBacktest)
            {
                handler.Update();
                i++;

                var sber = handler.GetLast(Symbols.Sber);
                var vtbr = handler.GetLast(Symbols.Vtbr);

                Console.WriteLine($"Iteration {i}");

                if (sber == null)
                {
                    Console.WriteLine($"{handler.CurrentTime} => SBER is NULL");
                }
                else
                {
                    sber.Print();
                }
                if (vtbr == null)
                {
                    Console.WriteLine($"{handler.CurrentTime} => VTBR is NULL");
                }
                else
                {
                    vtbr.Print();
                }
                Console.WriteLine("------------------");
            }
        }