Algorithm Statistics


The StatisticsResults object tracks all the statistics of your algorithm. You can access the statistics anywhere in your algorithm where you have a reference to the algorithm class.


The StatisticsResults object has the following properties:

Add Statistics

To add custom statistics to the StatisticsResults object, call the SetSummaryStatistic method with the statistic name and value.

SetSummaryStatistic("name", value);
self.SetSummaryStatistic("name", value)

Get Values

To get the StatisticsResults, use the Statistics member of the algorithm class.

var sharpe = Statistics.TotalPerformance.PortfolioStatistics.SharpeRatio;
sharpe = self.Statistics.TotalPerformance.PortfolioStatistics.SharpeRatio

To get the value of a custom statistic while your algorithm runs, index the Summary member with the statistic name. The values in the Summary dictionary are strings, so you may need to cast the value that returns to a different data type.

var value = Statistics.Summary["name"];
value = self.Statistics.Summary["name"]

The following table describe other ways to get the statistics after your backtest completes:

Deployment TargetAccess Tools
QuantConnect Cloud

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: