Optimization Scripts
A strategy portfolio can be assigned an optimization
script to optimize a preselected group of numeric script parameters belonging to
the portfolio scripts. (Trading strategy scripts,
position sizing scripts,
money management script…)
The optimization process runs the strategy portfolio
again and again using different parameter values, while calculating a goal value
at the end of each run. The selection of the parameter values for the next run as
well as the calculation of the goal value for the last run, are defined in the optimization
script itself.
Prior to running the optimization process the script parameters that require optimization
are selected and each parameter is assigned a range of possible values. The combination
of all possible values for all of the parameters selected for optimization creates
a list of optimization vectors that can be used to initialize the portfolio script
parameters.
For example:
If a trading strategy script parameter is selected
for optimization with a low range value of 1, a high range value of 2 and a step
value of 0.5 then the possible parameter values will be 1, 1.5 and 2.
If a position sizing script parameter is selected
for optimization with a low range value of 10, a high range value of 11 and a step
value of 0.25 then the possible parameter values will be 10, 10.25, 10.5, 10.75
and 11.
If both of these scripts are in the same strategy portfolio
and there are no other scripts with parameters selected for optimization, then the
optimization vectors for the portfolio will be:
<1,10>,<1,10.25>,<1,10.5>,<1,10.75><1,11>,<1.5,10>,<1.5,10.25>,<1.5,10.5>, <1.5,10.75>
<1.5,11>,<2,10>,<2,10.25>,<2,10.5>,<2,10.75><2,11>
The IQBroker automated trading software ships with a library of premade optimization scripts that can be parameterized
and customized without any programming, while custom scripts can be easily developed
using the resource designer and IQLanguage.
Script Implementation
|
OnInitialize()
|
|
This function is called automatically when the script is first initialized.
|
|
|
OnSelectVector() As Number()
|
|
This function is called prior to each portfolio run to select the optimization vector
values for the next portfolio run. The selected vector values are then used to argument
the portfolio scripts parameters immediately prior to running it.
|
|
|
OnScoreVector() As Number
|
|
This function is called after each portfolio run to evaluate the performance of
the portfolio and assign it a score based on its ability to meet a custom goal.
|
|
|
OnMaxVectors() As Integer
|
|
This function is called asynchronously to calculate the maximum number of vectors
to be optimized.
|
|