Automated Trading - Optimization


In Optimization mode, IQBroker fine-tunes the strategies by running hundreds or thousands of backtests, using many different combinations of parameters, to find the optimal set of parameters (usually, those that provide the most Net Profit).

After Optimization completes, you can update the strategies' parameters to use the best parameters that were discovered.

Optimization Settings

Edit Optimization Settings - configure how the optimization will run

View Optimization Results - after an optimization has run, show its results. (The results appear automatically at first; this button just shows them again.)

On this page:

Edit Optimization Settings

Settings Tab

Optimization Algorithm - determines which combinations of parameters to try

Optimization Score - which value to optimize for

Optimization Type - whether to use Standard of Walk-Forward optimization

Walk-Foward Settings - used if the optimization type is "Walk-Forward"

Performance Metric Results - which results to calculate on each run

Optimization Algorithm

The Optimization Algorithm is one of the most important settings, because it determines how many runs will be performed. There are three possible optimization algorithms:

Brute Force - tries every possible combination of parameters. Guaranteed to produce the absolute best result, but it's very slow.

Genetic - uses a genetic algorithm to reduce the number of runs. The number of runs = generations x chromosomes, e.g. 200.

Monte Carlo - uses a Monte Carlo algorithm to reduce the number of runs. The number of runs = num passes x runs per pass, e.g. 100.

Parameters Tab

Select which parameters to optimize, and the range of values to try for each parameter.

This tab shows all of the possible parameters that can be optimized. These parameters are taken from the Trading Strategies; Position Sizing scripts; Indicators; Dynamic Allocation scripts; etc. Only numeric parameters can be optimized. The more complex your porftolio, the more parameters will appear here.

Parameters that belong to the portfolio level are shown in the Portfolio tab, while parameters that belong to the Strategies are shown in Strategy tabs: Strategy 0, Strategy 1, etc.

In this example, only four parameters have been selected for optimization. All of the parameters belong to the Bollinger Bands Lower/Upper indicators, which are part of the Trading Strategy:

  • Bollinger Bands Lower Indicator - periods - range 5-50 in steps of 1 (46 possible values)
  • Bollinger Bands Lower Indicator - factor - range 1-3 in steps of 0.25 (9 possible values)
  • Bollinger Bands Upper Indicator - periods - range 5-50 in steps of 1 (46 possible values)
  • Bollinger Bands Upper Indicator - factor - range 1-3 in steps of 0.25 (9 possible values)

The total number of parameter combinations is: 46 x 9 x 46 x 9 = 171,396. If you selected the Brute Force optimization algorithm then this is the number of runs that will be performed. However, if you selected the Genetic or Monte-Carlo optimization algorithms then far fewer runs will be performed (typically 100-200). Furthermore, unlike the Brute Force algorithm, the number of runs performed by these algorithms is constant: it doesn't depend on the number of parameters that you have chosen to optimize.

Running an Optimization

To start the optimization, click Start:

Optimization Results

Once all of the runs have completed, the Optimization Results dialog appears:

This dialog shows each of the runs that were performed; the values that were used for each parameter; and the results of the run. This table is sorted by the Optimization Score, which we had chosen to be Net Profit.

The values that were used for each parameter appear in two places: a) In the Vector column; b) Below the results table.

Click Backtest Selected Optimization Run to save the values in the selected row to the Portfolio Strategy. Then, you can Backtest again using these values. The backtest runs immediately, and the Performance tab opens to show the results.

If you click on this button, and then look at the strategy's parameters, you'll see that they were updated to the selected values (12,1 and 5,3):

3D Chart

You can view a 3D chart that correlates two of the optimized parameters with one of the result parameters. This can provide insights about which ranges of parameters to concentrate on.

Heat Map

Another way to visualize the results is using a Heat Map.