Optimization

Getting Started

Introduction

Parameter optimization is the process of finding the optimal algorithm parameters to maximize or minimize an objective function. For instance, you can optimize your indicator parameters to maximize the Sharpe ratio that your algorithm achieves over a backtest. Optimization can help you adjust your strategy to achieve better backtesting performance, but be wary of overfitting. If you select parameter values that model the past too closely, your algorithm may not be robust enough to perform well using out-of-sample data.

Launch Optimization Jobs

Local Platform provides multiple deployment targets to enable you to run backtests on-premise and in QuantConnect Cloud.

You need the following to optimize parameters:

Follow these steps to optimize parameters:

  1. Open the project that contains the parameters you want to optimize.
  2. In the top-right corner of the IDE, click the Local optimization icon / Cloud optimization icon Optimize icon.
  3. On the Optimization page, in the Parameter & Constraints section, enter the name of the parameter to optimize.
  4. The parameter name must match a parameter name in the Project panel.

  5. Enter the minimum and maximum parameter values.
  6. Click the gear icon next to the parameter and then enter a step size.
  7. If you want to add another parameter to optimize, click Add Parameter.
  8. You can optimize a maximum of three parameters. To optimize more parameters, run local optimizations with the CLI.

  9. If you want to add optimization constraints, follow these steps:
    1. Click Add Constraint.
    2. Click the target field and then select a target from the drop-down menu.
    3. Click the operation field and then an operation from the drop-down menu.
    4. Enter a constraint value.
  10. If you are deploying to QuantConnect Cloud, in the Estimated Number and Cost of Backtests section, click an optimization node and then select a maximum number of nodes to use.
  11. In the Strategy & Target section, click the Choose Optimization Strategy field and then select a strategy from the drop-down menu.
  12. Click the Select Target field and then select a target from the drop-down menu.
  13. The target (also known as objective) is the performance metric the optimizer uses to compare the backtest performance of different parameter values.

  14. Click Maximize or Minimize to maximize or minimize the optimization target, respectively.
  15. Click Launch Optimization.
  16. The optimization results page displays. If you deploy a local optimization job, you can close Local Platform and Docker Desktop as the optimization job runs without interfering with the backtests. Just don't quit Docker Desktop. If you deploy the optimization job to QuantConnect Cloud, you can close Local Platform and Docker Desktop without interrupting with the backtests because the nodes are processing on our servers.

    To abort a running optimization job, in the Status panel, click Abort and then click Yes.

View Individual Backtest Results

The optimization results page displays a Backtests table that includes all of the backtests that ran during the optimization job. The table lists the parameter values of the backtests in the optimization job and their resulting values for the objectives.

Individual backtest result result

Open the Backtest Results Page

To open the backtest result page of one of the backtests in the optimization job, click a backtest in the table.

Download the Table

To download the table, right-click one of the rows, and then click Export > CSV Export.

Filter the Table

Follow these steps to apply filters to the Backtests table:

  1. On the right edge of the Backtests table, click Filters.
  2. Click the name of the column to which you want the filter to be applied.
  3. If the column you selected is numerical, click the operation field and then select one of the operations from the drop-down menu.
  4. Fill the fields below the operation you selected.
  5. Optimization results table

Toggle Table Columns

Follow these steps to hide and show columns in the Backtests table:

  1. On the right edge of the Backtests table, click Columns.
  2. Select the columns you want to include in the Backtests table and deselect the columns you want to exclude.

Sort the Table Columns

In the Backtests table, click one of the column names to sort the table by that column.

View All Optimizations

Follow these steps to view all of the optimization results of a project:

  1. Open the project that contains the optimization results you want to view.
  2. At the top of the IDE, click the / Results icon.
  3. A table containing all of the backtest and optimization 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 results.

    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 Optimizations

We give an arbitrary name (for example, "Smooth Apricot Chicken") to your optimization result files, but you can follow these steps to rename them:

  1. Hover over the optimization you want to rename and then click the pencil icon that appears.
  2. Rename optimization instance
  3. Enter the new name and then press Enter.

Delete Optimizations

Hover over the optimization you want to delete and then click the trash can icon that appears to delete the optimization result.

Delete optimization result

Result Files

To view the results files of a local optimization job, open the <organizationWorkspace> / <projectName> / optimizations / <optimizationName> directory. The following table describes the initial contents of the optimization result directories:

File/DirectoryDescription
code /A directory containing a copy of the files that were in the project when you ran the optimization.
<backtestId> /
Ex: 1c5b8eff-89c0-432f-98c7-60b73265b188 /
A directory containing the backtest result files for one of the backtest in the optimization job. There is separate directory for each backtest in the optimization job.
log.txtA file containing the syslog.
configA file containing some configuration settings, including the optimization Id, Docker container name, and optimization name.
optimizer-config.jsonA file containing some configuration settings, including the parameters, strategy, and constrains.
optimization-result-<optimizationId>.json
Ex: optimization-result-2455523408.json
A file containing additional results, including runtime statistics.

Algorithm Lab Optimizations

For information about cloud optimizations through the Algorithm Lab, see Getting Started.

Get Optimization Id

To get the optimization Id, open the optimization result page and then scroll down to the table that shows the individual backtest results. The optimization Id is at the top of the table. An example local optimization Id is 2726379566. An example cloud optimization Id is O-696d861d6dbbed45a8442659bd24e59f.

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: