Optimization strategies control how the optimizer adjusts parameters for each new backtest that's run in the optimization job. Grid search is the only strategy currently available, but you can contribute new optimization strategies.

Grid Search

Grid search is the most complete but the most expensive strategy because it takes a brute force approach and tests all the combinations of parameter values. If you are optimizing one parameter, the grid search strategy selects the values of the parameters based on the starting value, ending value, and step size that you provide. If you optimize two parameters, the grid search strategy searches the Cartesian product of possible values for each parameter. The following animation shows the process of using grid search to optimize two parameters:

Grid search animation

In the preceding animation, grid search tests all of the parameter combinations. The axes represent the possible values of each parameter. Gray squares represent backtests in the optimization queue, orange squares represent successful backtests, and black squares represent failed backtests. In this example, several squares are colored at the same time because the optimization job is using multiple optimization nodes.

Why Backtests Fail

When backtests fail during optimization, it is usually because the selected parameter values cause a divide-by-zero error or an index out-of-range exception.

Strategy Benefit and Drawback

The benefit of the grid search strategy is that it is the most comprehensive optimization strategy. The drawback of the strategy is it can be an expensive option because of the curse of dimensionality.

Contribute Strategies

You can contribute any optimization strategy that is popular in the literature and is not already implemented. To view the optimization strategies that are already implemented, see our GitHub repository. If you contribute a strategy, you'll receive some QuantConnect Credit, you'll be shown as a contributor to Lean on your GitHub profile, and your work will be used in the Algorithm Lab by our community of over 250,000 quants.

To contribute optimization strategies, submit a pull request to the Lean GitHub repository. In your pull request, provide an explanation of the strategy and some relevant resources so that we can add the strategy to our documentation. For an example implementation, see the GridSearchOptimizationStrategy.

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: