Ejemplo n.º 1
0
        public SessionModel(HubConfigurationModel hubConfig, BrokerConfigurationModel brokerConfig,
                            ResponseConfigurationModel responseConfig, ReportConfigurationModel reportConfig)
        {
            _hub          = DarkLightFactory.GetHub(hubConfig);
            _broker       = DarkLightFactory.GetBroker(_hub, brokerConfig);
            _responseList = DarkLightFactory.GetResponseList(_hub, responseConfig);
            _reporter     = DarkLightFactory.GetReporter(_hub, reportConfig);
            //_riskMgr = DarkLightFactory.GetRiskManager(_hub, reportConfig);
            //_portfolioMgr = DarkLightFactory.GetPortfolioManager(_hub, reportConfig);

            //_hub.EventDict[EventType.ReportMessage]
        }
Ejemplo n.º 2
0
        public static IDarkLightBroker GetBroker(IHub hub, BrokerConfigurationModel config)
        {
            switch (config.Type)
            {
            case BrokerType.Sim:
                return(new DarkLightSimBroker(hub, config));

            case BrokerType.Live:
                return(new DarkLightSimBroker(hub, config));

            default:
                return(new DarkLightSimBroker(hub, config));
            }
        }
Ejemplo n.º 3
0
        public DarkLightSimBroker(IHub hub, BrokerConfigurationModel config)
            : base(hub, config)
        {
            //Plug into Tradelink
            _broker = new Broker();
            _broker.UseBidAskFills  = config.SimUseBidAskFills;
            _broker.GotFill        += PublishFill;
            _broker.GotOrder       += PublishOrderAck;
            _broker.GotOrderCancel += PublishOrderCancelAck;

            loadTickData(config.TickFiles);
            _historicalSimulator          = new MultiSimImpl(_historicalDataFiles.ToArray());
            _historicalSimulator.GotTick += PublishTick;

            //Set up tick player
            _backgroundWorker         = new BackgroundWorker();
            _backgroundWorker.DoWork += play;
            _backgroundWorker.WorkerReportsProgress      = false;
            _backgroundWorker.WorkerSupportsCancellation = true;
            _backgroundWorker.RunWorkerCompleted        += playComplete;

            _playTo = config.PlayToValue;
        }
        private void RunBacktestButton_Click2(object sender, System.Windows.RoutedEventArgs e)
        {
            UnbindInitializationModels();
            UnbindReportModels();

            _backtest2.Clear();
            _activityModel.Status = "Backtest started.";
            var tickDataGroups = BacktestingTickFileControl.GetSelectedFilePaths();

            _activityModel.NumberTestsToRun     = tickDataGroups.Count;
            _activityModel.NumberTestsCompleted = 0;

            Task.Factory.StartNew(() =>
            {
                _activityModel.AllRunsCompleted.WaitOne();
                if (_backtest2.BacktestReports.Any())
                {
                    _backtest2.SelectedReport = _backtest2.BacktestReports.First();
                    BindStatisticsModels2("Results");
                }
            });

            foreach (var _tickDataGroup in tickDataGroups)
            {
                var hubConfig = new HubConfigurationModel(HubType.Local);

                var brokerConfig = new BrokerConfigurationModel(BrokerType.Sim);
                brokerConfig.PlayToValue       = _backtestingConfigurationModel.SelectedPlayToValue;
                brokerConfig.SimUseBidAskFills = false;
                brokerConfig.TickFiles         = _tickDataGroup;
                brokerConfig.SubscriptionList  = new List <byte[]> {
                    EventType.Basket, EventType.CancelOrder, EventType.Order
                };

                var responseConfig = new ResponseConfigurationModel();
                responseConfig.ResponseList.Add(_backtestingConfigurationModel.GetFreshResponseInstance());
                responseConfig.SubscriptionList = new List <byte[]> {
                    EventType.CancelOrderAck, EventType.Fill, EventType.Message, EventType.OrderAck, EventType.Tick
                };

                var reportConfig = new ReportConfigurationModel();
                reportConfig.Type             = ReportType.Batch;
                reportConfig.ActivityInstance = _activityModel;
                var info = TickFileNameInfo.GetTickFileInfoFromLongName(_tickDataGroup.First());
                reportConfig.ReportName       = "Y:" + info.Year.ToString() + ",M:" + info.Month.ToString() + ",D:" + info.Day.ToString();
                reportConfig.SubscriptionList = new List <byte[]> {
                    EventType.ChartLabel, EventType.Fill, EventType.Indicator, EventType.Message, EventType.Order, EventType.ServiceTransition, EventType.Tick
                };
                reportConfig.FilterMode = true;

                var sessionModel = new SessionModel(hubConfig, brokerConfig, responseConfig, reportConfig);

                _backtest2.AddRun(sessionModel);

                sessionModel.Reporter.RegisterDispatcher(EventType.Fill, FillsTab.Dispatcher);
                sessionModel.Reporter.RegisterDispatcher(EventType.Indicator, IndicatorTab.Dispatcher);
                sessionModel.Reporter.RegisterDispatcher(EventType.Message, MessagesTab.Dispatcher);
                sessionModel.Reporter.RegisterDispatcher(EventType.Order, OrdersTab.Dispatcher);
                sessionModel.Reporter.RegisterDispatcher(EventType.Plot, BacktestPlotter.Dispatcher);
                sessionModel.Reporter.RegisterDispatcher(EventType.Position, PositionTab.Dispatcher);
            }

            BindInitializationModels2();
            _backtest2.Start(0);
        }