Statistics

Algorithm Statistics

Introduction

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 and the number of trading days per year.

Properties

The StatisticsResults object has the following properties:

Add Statistics

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

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

Get Values

To get the StatisticsResults, use the Statisticsstatistics 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 Summarysummary member with the statistic name. The values in the Summarysummary 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
Local

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: