public void SendFinalResult(AlgorithmNodePacket job, Dictionary <int, Order> orders, Dictionary <DateTime, decimal> profitLoss, Dictionary <string, Holding> holdings, CashBook cashbook, StatisticsResults statisticsResults, Dictionary <string, string> banner) { _shadow.SendFinalResult(job, orders, profitLoss, holdings, cashbook, statisticsResults, banner); if (_hasError) { FullResults = null; return; } FullResults = StatisticsAdapter.Transform(statisticsResults.TotalPerformance, statisticsResults.Summary); }
public void SendFinalResult(AlgorithmNodePacket job, Dictionary <int, Order> orders, Dictionary <DateTime, decimal> profitLoss, Dictionary <string, Holding> holdings, StatisticsResults statisticsResults, Dictionary <string, string> banner) { _shadow.SendFinalResult(job, orders, profitLoss, holdings, statisticsResults, banner); FullResults = StatisticsAdapter.Transform(statisticsResults.TotalPerformance); }
//HACK: calculate and retain full statistics but not store result public void SendFinalResult() { if (_hasError) { FullResults = null; return; } try { //_processingFinalPacket = true; _shadowType.GetField("_processingFinalPacket", _flags).SetValue(_shadow, true); var charts = new Dictionary <string, Chart>(_shadow.Charts); //var orders = new Dictionary<int, Order>(_shadow.TransactionHandler.Orders); var transactionHandler = (ITransactionHandler)_shadowType.GetField("TransactionHandler", _flags).GetValue(_shadow); var orders = new Dictionary <int, Order>(transactionHandler.Orders); var profitLoss = new SortedDictionary <DateTime, decimal>(Algorithm.Transactions.TransactionRecord); //var statisticsResults = GenerateStatisticsResults(charts, profitLoss); var statisticsResults = (StatisticsResults)_shadowType.InvokeMember("GenerateStatisticsResults", _flags | BindingFlags.InvokeMethod, null, _shadow, new object[] { charts, profitLoss }); //var runtime = GetAlgorithmRuntimeStatistics(statisticsResults.Summary); var runtime = (Dictionary <string, string>) typeof(BaseResultsHandler).InvokeMember("GetAlgorithmRuntimeStatistics", _flags | BindingFlags.InvokeMethod, Type.DefaultBinder, _shadow, new object[] { statisticsResults.Summary, null }); FullResults = StatisticsAdapter.Transform(statisticsResults.TotalPerformance, statisticsResults.Summary); //FinalStatistics = statisticsResults.Summary; _shadowType.GetProperty("FinalStatistics").SetValue(_shadow, statisticsResults.Summary, _flags, null, null, null); foreach (var ap in statisticsResults.RollingPerformances.Values) { ap.ClosedTrades.Clear(); } //var result = new BacktestResultPacket(_job, // new BacktestResult(charts, orders, profitLoss, statisticsResults.Summary, runtime, statisticsResults.RollingPerformances, statisticsResults.TotalPerformance) // { AlphaRuntimeStatistics = AlphaRuntimeStatistics }, Algorithm.EndDate, Algorithm.StartDate) //{ // ProcessingTime = (DateTime.UtcNow - StartTime).TotalSeconds, // DateFinished = DateTime.Now, // Progress = 1 //}; var job = (BacktestNodePacket)_shadowType.GetField("_job", _flags).GetValue(_shadow); var startTime = (DateTime)_shadowType.GetProperty("StartTime", _flags).GetValue(_shadow); var alphaRuntimeStatistics = (AlphaRuntimeStatistics)_shadowType.GetProperty("AlphaRuntimeStatistics", _flags).GetValue(_shadow); var result = new BacktestResultPacket(job, new BacktestResult(charts, orders, profitLoss, statisticsResults.Summary, runtime, statisticsResults.RollingPerformances, statisticsResults.TotalPerformance) { AlphaRuntimeStatistics = alphaRuntimeStatistics }, Algorithm.EndDate, Algorithm.StartDate) { ProcessingTime = (DateTime.UtcNow - startTime).TotalSeconds, DateFinished = DateTime.Now, Progress = 1 }; //StoreResult(result); //do not store result //MessagingHandler.Send(result); var messagingHandler = (IMessagingHandler)_shadowType.GetField("MessagingHandler", _flags).GetValue(_shadow); messagingHandler.Send(result); } catch (Exception ex) { LogProvider.ErrorLogger.Error(ex); } }