Backtesting
Results
View Backtest Results
The backtest results page automatically displays when you deploy a backtest. The backtest results page presents the equity curve, trades, logs, performance statistics, and much more information.
The content in the backtest results page updates as your backtest executes. You can close or refresh the window without interrupting the backtest because the backtesting node processes on our servers. If you close the page, to open the page again, view all of the project's backtests. Unless you explicitly make the backtest public, only you can view its results. If you delete a backtest result or you are inactive for 12 months, we archive your backtest results.
Runtime Statistics
The banner at the top of the backtest results page displays the runtime statistics of your backtest.
The following table describes the default runtime statistics:
Statistic | Description |
---|---|
Equity | The total portfolio value if all of the holdings were sold at current market rates. |
Fees | The total quantity of fees paid for all the transactions. |
Holdings | The absolute sum of the items in the portfolio. |
Net Profit | The dollar-value return across the entire trading period. |
PSR | The probability that the estimated Sharpe ratio of an algorithm is greater than a benchmark (1). |
Return | The rate of return across the entire trading period. |
Unrealized | The amount of profit a portfolio would capture if it liquidated all open positions and paid the fees for transacting and crossing the spread. |
Volume | The total value of assets traded for all of an algorithm's transactions. |
To download the runtime statistics data, see Download Results.
To add a custom runtime statistic, see Add Statistics.
Built-in Charts
The backtest results page displays a set of built-in charts to help you analyze the performance of your algorithm. The following table describes the charts displayed on the page:
Chart | Description |
---|---|
Strategy Equity | A time series of equity and periodic returns. |
Capacity | A time series of strategy capacity snapshots. |
Drawdown | A time series of equity peak-to-trough value. |
Benchmark | A time series of the benchmark closing price (SPY, by default). |
Exposure | A time series of long and short exposure ratios. |
Assets Sales Volume | A chart showing the proportion of total volume for each traded security. |
Portfolio Turnover | A time series of the portfolio turnover rate. |
Portfolio Margin | A stacked area chart of the portfolio margin usage. For more information about this chart, see Portfolio Margin Plots. |
Asset Plot | A time series of an asset's price with order event annotations. These charts are available for all paid organziation tiers. For more information about these charts, see Asset Plots. |
To download the chart data, see Download Results.
Asset Plots
Asset plots display the trade prices of an asset and the following order events you have for the asset:
Order Event | Icon |
---|---|
Submissions | Gray circle |
Updates | Blue circle |
Cancellations | Gray square |
Fills and partial fills | Green (buys) or red (sells) arrows |
The following image shows an example asset plot for AAPL:
The order submission icons aren't visible by default.
View Plots
Follow these steps to open an asset plot:
- Open the backtest results page.
- Click the Orders tab.
- Click the Asset Plot icon that's next to the asset Symbol in the Orders table.
Tool Tips
When you hover over one of the order events in the table, the asset plot highlights the order event, displays the asset price at the time of the event, and displays the tag associated with the event. Consider adding helpful tags to each order event to help with debugging your algorithm. For example, when you cancel an order, you can add a tag that explains the reason for cancelling it.
Adjust the Display Period
The resolution of the asset price time series in the plot doesn't necessarily match the resolution you set when you subscribed to the asset in your algorithm. If you are displaying the entire price series, the series usually displays the daily closing price. However, when you zoom in, the chart will adjust its display period and may use higher resolution data. To zoom in and out, perform either of the following actions:
- Click the , , , or period in the top-right corner of the chart.
- Click a point on the chart and drag your mouse horizontally to highlight a specific period of time in the chart.
If you have multiple order events in a single day and you zoom out on the chart so that it displays the daily closing prices, the plot aggregates the order event icons together as the price on that day.
Order Fill Prices
The plot displays fill order events at the actual fill price of your orders. The fill price is usually not equal to the asset price that displays because of the following reasons:
- Your order experiences slippage.
- If you use quote data, your order fills at the bid or ask price.
- The fill model may fill your order at the high or low price.
Custom Charts
The results page shows the custom charts that you create.
Supported Chart Types
We support the following types of charts:
If you use SeriesType.Candle
and plot enough values, the plot displays candlesticks. However, the Plot
plot
method only accepts one numerical value per time step, so you can't plot candles that represent the open, high, low, and close values of each bar in your algorithm. The charting software automatically groups the data points you provide to create the candlesticks, so you can't control the period of time that each candlestick represents.
To create other types of charts, save the plot data in the Object Store and then load it into the Research Environment. In the Research Environment, you can create other types of charts with third-party charting packages.
Supported Markers
When you create scatter plots, you can set a marker symbol. We support the following marker symbols:
Chart Quotas
Intensive charting requires hundreds of megabytes of data, which is too much to stream online or display in a web browser. The number of series and the number of data points per series you can plot depends on your organization tier. The following table shows the quotas:
Tier | Max Series | Max Data Points per Series |
---|---|---|
Free | 10 | 4,000 |
Quant Researcher | 10 | 8,000 |
Team | 25 | 16,000 |
Trading Firm | 25 | 32,000 |
Institution | 100 | 96,000 |
If you exceed the series quota, your algorithm stops executing and the following message displays:
If you exceed the data points per series quota, the following message displays:
If your plotting needs exceed the preceding quotas, create the plots in the Research Environment instead.
Demonstration
For more information about creating custom charts, see Charting.
Adjust Charts
You can manipulate the charts displayed on the backtest results page.
Toggle Charts
To display and hide a chart on the backtest results page, in the Select Chart section, click the name of a chart.
Toggle Chart Series
To display and hide a series on a chart on the backtest results page, click the name of a series at the top of a chart.
Adjust the Display Period
To zoom in and out of a time series chart on the backtest results page, perform either of the following actions:
- Click the , , , or period in the top-right corner of the chart.
- Click a point on the chart and drag your mouse horizontally to highlight a specific period of time in the chart.
If you adjust the zoom on a chart, it affects all of the charts.
After you zoom in on a chart, slide the horizontal bar at the bottom of the chart to adjust the time frame that displays.
Resize Charts
To resize a chart on the backtest results page, hover over the bottom-right corner of the chart. When the resize cursor appears, hold the left mouse button and then drag to the desired size.
Move Charts
To move a chart on the backtest results page, click, hold, and drag the chart title.
Refresh Charts
Refreshing the charts on the backtest results page resets the zoom level on all the charts. If you refresh the charts while your algorithm is executing, only the data that was seen by the Lean engine after you refreshed the charts is displayed. To refresh the charts, in the Select Chart section, click the reset icon.
Key Statistics
The backtest results page displays many key statistics to help you analyze the performance of your algorithm.
Overall Statistics
The Overview tab on the backtest results page displays tables for Overall Statistics and Rolling Statistics. The Overall Statistics table displays the following statistics:
- Probabilistic Sharpe Ratio (PSR)
- Total Trades
- Average Loss
- Drawdown
- Net Profit
- Loss Rate
- Profit-Loss Ratio
- Beta
- Annual Variance
- Tracking Error
- Total Fees
- Lowest Capacity Asset
- Sharpe Ratio
- Average Win
- Compounding Annual Return
- Expectancy
- Win Rate
- Alpha
- Annual Standard Deviation
- Information Ratio
- Treynor Ratio
- Estimated Strategy Capacity
Some of the preceding statistics are sampled throughout the backtest to produce a time series of rolling statistics. The time series are displayed in the Rolling Statistics table.
To download the data from the Overall Statistics and Rolling Statistics tables, see Download Results.
Ranking
The backtest results page displays a Ranking section that shows the PSR and rank (percentile) of your algorithm.
The rank of your algorithm is calculated as
$$ CDF\left(\frac{PSR_{algo} - \overline{PSR}}{\sigma_{PSR}}\right) $$where $CDF$ is the normal cumulative distribution function and $PSR_{algo}$ is your algorithm's PSR. $\overline{PSR}$ and $\sigma_{PSR}$ are the mean PSR and the standard deviation of PSR values, respectively, calculated from all of the backtests that have the following attributes:
- Occurred in the last 30 days
- Had more than 90 tradable days
- Had a PSR value in the interval (0, 100)
Research Guide
For information about the Research Guide, see Research Guide.
Reports
Backtest reports provide a summary of your algorithm's performance during the backtest period. Follow these steps to generate one:
- Open the backtest results page for which you want to generate a report.
- Click the Report tab.
- If the project doesn't have a description, enter one and then click .
- Click .
- If the IDE says that the report is being generated, repeat step 4.
The report may take a minute to generate.
Orders
The backtest results page displays the orders of your algorithm and you can download them to your local machine.
View in the GUI
To see the orders that your algorithm created, open the backtest results page and then click the Orders tab. If there are more than 10 orders, use the pagination tools at the bottom of the Orders Summary table to see all of the orders. Click on an individual order in the Orders Summary table to reveal all of the order events, which include:
- Submissions
- Fills
- Partial fills
- Updates
- Cancellations
- Option contract exercises and expiration
The timestamps in the Order Summary table are based in Eastern Time (ET).
Access the Order Summary CSV
To view the orders data in CSV format, open the backtest results page, click the Orders tab, and then click . The content of the CSV file is the content displayed in the Orders Summary table when the table rows are collapsed. The timestamps in the CSV file are based in Coordinated Universal Time (UTC).
Access the Orders JSON
To view all of the content in the Orders Summary table, see Download Results.
Access in Jupyter Notebooks
To programmatically analyze orders, call the ReadBacktestOrdersread_backtest_orders method or the /backtests/orders/read endpoint.
Insights
The backtest results page displays the insights of your algorithm and you can download them to your local machine.
View in the GUI
To see the insights your algorithm emit, open the backtest result page and then click the Insights tab. If there are more than 10 insights, use the pagination tools at the bottom of the Insights Summary table to see all of the insights. The timestamps in the Insights Summary table are based in Eastern Time (ET).
Download JSON
To view the insights in JSON format, open the backtest result page, click the Insights tab, and then click . The timestamps in the CSV file are based in Coordinated Universal Time (UTC).
Logs
The backtest results page displays the logs of your backtest and you can download them to your local machine. The timestamps of the statements in the log file are based in your algorithm time zone.
View in the GUI
To see the log file that was created throughout a backtest, open the backtest result page and then click the Logs tab.
To filter the logs, enter a search string in the Filter logs field.
Download Log Files
To download the log file that was created throughout a backtest, follow these steps:
- Open the backtest result page.
- Click the Logs tab.
- Click .
Share Results
The backtest results page enables you to share your backtest results. You need to make a backtest public in order to share it. To make a backtest public, on the backtest results page, click the Share tab and then click . Once you make a backtest public, the Share tab displays a link to the backtest report, a link to an embedded backtest result, and a script to embed the embedded backtest result into a website.
The following widget is an example of an embedded backtest result:
To attach the embedded backtest result to a forum discussion, see Create Discussions or Post Comments.
After you've made your backtest results public, the results are always stored, anyone with the link can access the results, and the results can't be made private again because someone may have already cloned your project.
Download Results
You can download the following information from the backtest results page:
- Runtime statistics
- Charts
- The data in the Overview tab
- The data in the Orders tab
To download the preceding information, open the backtest results page, click the Overview tab, and then click . The timestamps in the file are based in Coordinated Universal Time (UTC).
View All Backtests
Follow these steps to view all of the backtests of a project:
- Open the project that contains the backtests you want to view.
- In the top-right corner of the IDE, click the Backtest Results icon.
- (Optional) In the top-right corner, select the Show field and then select one of the options from the drop-down menu to filter the table by backtest or optimization results.
- (Optional) In the bottom-right corner, click the Hide Error check box to remove backtest and optimization results from the table that had a runtime error.
- (Optional) Use the pagination tools at the bottom to change the page.
- (Optional) Click a column name to sort the table by that column.
- Click a row in the table to open the results page of that backtest or optimization.
A table containing all of the backtest results for the project is displayed. If there is a play icon to the left of the name, it's a backtest result. If there is a fast-forward icon next to the name, it's an optimization result.
Rename Backtests
We give an arbitrary name (for example, "Smooth Apricot Chicken") to your backtest result files, but you can follow these steps to rename them:
- Hover over the backtest you want to rename and then click the pencil icon that appears.
- Enter the new backtest name and then click .
To programmatically set the backtest name, call the SetName
set_name
method.
SetName("Backtest Name");
self.set_name("Backtest Name")
For more information, see Set Name and Tags.
Clone Backtests
Hover over the backtest you want to clone, and then click the clone icon that appears to clone the backtest.
A new project is created with the backtest code files.
Delete Backtests
Hover over the backtest you want to delete, and then click the trash can icon that appears to delete the backtest.
Out of Sample Period
To reduce the chance of overfitting, organization managers can enforce all backtests must end a certain number of months before the current date. For example, if you set a one year out-of-sample period, the researchers on your team will not be able to use the most recent year of data in their backtests. A out-of-sample period is helpful because it leaves you a period to test your model after your done the development stage. Follow these steps to change the backtest out-of-sample period:
- Open the organization homepage.
- Scroll down to the Backtesting Out of Sample Period section.
- Adjust the out-of-sample period duration or click on "No Holdout Period".