Backtesting

Getting Started

Introduction

Backtesting is the process of simulating a trading algorithm on historical data. By running a backtest, you can measure how the algorithm would have performed in the past. Although past performance doesn't guarantee future results, an algorithm that has a proven track record can provide investors with more confidence when deploying to live trading than an algorithm that hasn't performed favorably in the past. Use the QuantConnect platform to run your backtests because we have institutional-grade datasets, an open-source backtesting engine that's constantly being improved, cloud servers to execute the backtests, and the backtesting hardware is maintained 24/7 by QuantConnect engineers.

Run Backtests

To run a backtest, open a project and then click the Backtest icon. If the project successfully builds, "Received backtest backtestName request" displays. If the backtest successfully launches, the IDE displays the backtest results page in a new tab. If the backtest fails to launch due to coding errors, the new tab displays the error. As the backtest executes, you can refresh or close the IDE without interfering with the backtest because it runs on our cloud servers. The backtest runs up to the start of the out-of-sample hold out period.

View All Backtests

Follow these steps to view all of the backtests of a project:

  1. Open the project that contains the backtests you want to view.
  2. In the top-right corner of the IDE, click the Backtest Results icon.
  3. 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.

    All backtest table view
  4. (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.
  5. (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.
  6. (Optional) Use the pagination tools at the bottom to change the page.
  7. (Optional) Click a column name to sort the table by that column.
  8. Click a row in the table to open the results page of that backtest or optimization.

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:

  1. Open the backtest history of the project.
  2. Hover over the backtest you want to rename and then click the pencil icon that appears.
  3. Rename backtest navigation
  4. Enter the new backtest name and then click OK.

To programmatically set the backtest name, call the SetNameset_name method.

SetName("Backtest Name");
self.set_name("Backtest Name")

For more information, see Set Name and Tags.

On-Premise Backtests

For information about on-premise backtests with Local Platform, see Getting Started.

Get Backtest Id

To get the backtest Id, see the first line of the log file. An example backtest Id is 8b16cec0c44f75188d82f9eadb310e17.

Share Backtests

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 Make Public. 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.

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: