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. Some of these statistics are a function of the risk free interest rate.


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.set_summary_statistic("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.total_performance.portfolio_statistics.sharpe_ratio

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: