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

The following video demonstrates how to launch an optimization job:

You need the following to optimize parameters:

  • At least one algorithm parameter in your project.
  • The GetParameter method or Parameter attribute in your project.
  • A successful backtest of the project.
  • QuantConnect Credit (QCC) in your organization.

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 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 a second parameter to optimize, click Add Parameter.
  8. You can optimize a maximum of two parameters. To optimize more parameters, run local optimizations.

  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. In the Estimated Number and Cost of Backtests, click an optimization node.
  11. Select a maximum number of nodes to use.
  12. In the Estimated Number and Cost of Backtests, click the Choose Optimization Strategy field and then select a strategy from the drop-down menu.
  13. Click the Select Target field and then select a target from the drop-down menu.
  14. The target (also known as objective) is the performance metric the optimizer uses to compare the backtest performance of different parameter values.

  15. Click Maximize or Minimize to maximize or minimize the optimization target, respectively.
  16. Click Launch Optimization.
  17. The optimization results page displays. As the optimization job runs, you can close or refresh the window without interrupting the job 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.

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.

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 result.

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

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: