Difference between revisions of "Performing Optimization"

From MultiCharts
Jump to navigation Jump to search
 
(8 intermediate revisions by 3 users not shown)
Line 8: Line 8:
 
To perform Exhaustive Search optimization:  
 
To perform Exhaustive Search optimization:  
  
# Open the '''Format Objects''' window.<br><span>{{FormatObjectIS}}</span>
+
:1. Open the '''Format Objects''' window.<br><span>{{FormatObjectIS}}</span>
# Select the '''Signals''' tab.
+
:2. Select the '''Signals''' tab.
# Click the '''Optimize''' button.
+
:3. Click the '''Optimize''' button.
# In the '''Select Optimization Method''' dialog box that appears, select '''Exhaustive Search'''.
+
:4. In the '''Choose the Optimization Type''' dialog box that appears, select '''Regular Optimization''' and click '''Next'''.
# In the '''Exhaustive Search Properties''' window that opens, select the '''Optimizable Inputs''' tab.
+
:5. In the '''Set Optimizable Inputs''' section check/uncheck the check box to the left of the signal name and input name to enable/disable optimization for this input or check the check box to the left of the '''Signal Name''' column heading to enable optimization for all inputs (at least one input should be selected to perform optimization).  
# Check/uncheck the check box to the left of the signal name and input name to enable/disable optimization for this input or check the check box to the left of the '''Signal Name''' column heading to enable optimization for all inputs (at least one input should be selected to perform optimization).  
+
:6. The '''Current Value''' column shows input values that are currently selected for the signals applied on the chart.
# The '''Current Value''' column shows input values that are currently selected for the signals applied on the chart.
+
:7. In the '''Start Value''' column, enter the desired starting values for each of the inputs.
# In the '''Start Value''' column, enter the desired starting values for each of the inputs.
+
:8. In the '''End Value''' column, enter the desired ending values for each of the inputs.
# In the '''End Value''' column, enter the desired ending values for each of the inputs.
+
:9. In the '''Step''' column, enter the desired step size, for each of the inputs.
# In the '''Step''' column, enter the desired step size, for each of the inputs.
+
:10. The '''Step Count''' column shows current number of steps for an input.  
# The '''Step Count''' column shows current amount of steps for an input.  
+
:11. Select '''Exhaustive''' radio button in the '''Set Optimization Method''' section.
# Select the '''Optimization Criteria''' tab.
+
:12. Select the target function to be optimized in '''Optimize by''' section:
# Select the '''Use Limitation''' checkbox to limit the output to a defined number of the best results; unselect the checkbox to list all the results in the optimization report.
+
In the '''Maximal/Minimal''' list, set the respective values to be selected at the end of optimization.
# When '''Use Limitation''' checkbox is checked Optimization dialog window shows current best results for selected сriteria during optimization.
+
From the next list one can select the function itself.
# Enter the desired number of best results in the '''Show <i>N</i> best results''' box.
+
<br>If '''Custom Criteria''' is selected, Edit button is available. Press it to write the script for the custom criteria. [[Performing_Optimization#Custom Criteria|Read more about Standard and Custom Criteria]].
# Select the best results criteria in the '''best results for''' list box.
+
<br>In order to apply the desired function from code select '''Custom Fitness Value'''. The custom value shall be specified by [[SetCustomFitnessValue]] keyword in the script.
# Select criteria:
+
:13. Select the '''Use Limitation''' checkbox to limit the output to a defined number of the best results; unselect the checkbox to list all the results in the optimization report.
#: 1. Select '''Standard Criteria'''.
+
:14. When '''Use Limitation''' checkbox is checked Optimization dialog window shows current best results for selected сriteria during optimization.
#: 2. Select the criteria from the drop-down list. [[Performing_Optimization#Standard Criteria|Read more about Standard Criteria]].<br>or:<br>
+
:15. Click '''Optimize''' N '''combinations''' to run the optimization and generate the Optimization Report.
#: 1. Select '''Custom Criteria'''.
+
<br>
#: 2. Click '''Edit...''' button.
 
#: 3. Write the script for the custom criteria. [[Performing_Optimization#Custom Criteria|Read more about Custom Criteria]].
 
#: 4. Click '''OK'''.
 
# Select '''Ascending''' or '''Descending''' option to sort the output in ascending or descending order, respectively.
 
# Click '''OK''' to run the optimization and generate the Optimization Report.
 
 
 
 
<div style="background-color: #E3FBE5;">Since '''MultiCharts 10''' that is possible to start optimization from '''Chart Analysis''' toolbar (see [[MultiCharts_Work_Area#Hiding_and_Redisplaying_Toolbars]]) by clicking on the '''Optimize Strategy''' button: [[File:toolbar2_ChartAn_125.png]]</div>
 
<div style="background-color: #E3FBE5;">Since '''MultiCharts 10''' that is possible to start optimization from '''Chart Analysis''' toolbar (see [[MultiCharts_Work_Area#Hiding_and_Redisplaying_Toolbars]]) by clicking on the '''Optimize Strategy''' button: [[File:toolbar2_ChartAn_125.png]]</div>
  
Line 45: Line 39:
  
 
To perform Genetic Algorithm optimization:  
 
To perform Genetic Algorithm optimization:  
 +
:1. Open the '''Format Objects''' window.<br><span>{{FormatObjectIS}}</span>
 +
:2. Select the '''Signals''' tab.
 +
:3. Click the '''Optimize''' button.
 +
:4. In the '''Choose the Optimization Type''' dialog box that appears, select '''Regular Optimization''' and click '''Next'''.
 +
:5. In the '''Set Optimizable Inputs''' section check/uncheck the check box to the left of the signal name and input name to enable/disable optimization for this input or check the check box to the left of the '''Signal Name''' column heading to enable optimization for all inputs (at least one input should be selected to perform optimization).
 +
:6. The '''Current Value''' column shows input values that are currently selected for the signals applied on the chart.
 +
:7. In the '''Start Value''' column, enter the desired starting values for each of the inputs.
 +
:8. In the '''End Value''' column, enter the desired ending values for each of the inputs.
 +
:9. In the '''Step''' column, enter the desired step size, for each of the inputs.
 +
:10. The '''Step Count''' column shows current number of steps for an input.
 +
:11. Select '''Genetic''' radio button in the '''Set Optimization Method''' section.
 +
:12. Selecting the target function to be optimized in the '''Optimize by:''' section:
 +
In the '''Maximal/Minimal''' list, set the respective individuals, which will take part in further selection and crossover, for the selected parameter.
 +
From the next list one can select the function itself.
 +
<br>If '''Custom Criteria''' is selected, Edit button is available. Press it to write the script for the custom criteria. [[Performing_Optimization#Custom Criteria|Read more about Standard and Custom Criteria]].
 +
<br>In order to apply the desired function from code select '''Custom Fitness Value'''. The custom value shall be specified by [[SetCustomFitnessValue]] keyword in the script.
 +
 +
:13. Set Basic Genetic Algorithm Parameters.
 +
:14. An optimum population size value is automatically placed next to the '''Set Population Size''' box; if a different value is desired, check '''Set Population Size''' box and select the value.
 +
:15. In the '''Crossover Probability''' field, select the desired crossover probability; value range is 0-1, with a default of 0.95.
 +
:16. In the '''Mutation Probability''' field, select the desired mutation probability; value range is 0-1, with a default of 0.05.
 +
:17. In the '''Convergence Type''' section, select '''Number of Generations''' or '''Proximal Convergence'''.
 +
:18. If '''Number of Generations''' is selected:
 +
In the '''Number of Individuals in Population for Crossover''' field, enter the desired number of individuals in population for crossover.
 +
<br>In the '''Maximum Number of Generations''' field, enter the desired maximum number of generations.
 +
<br>
 +
<div style="background-color: #E3FBE5;">Note: the above fields are grayed out if “Set Population Size” box is not checked in Basic Genetic Algorithm Parameters.</div>
 +
:19. If '''Proximal Convergence''' is selected:
 +
In the '''Number of Individuals in Population for Crossover''' field, enter the desired number of individuals in population for crossover.
 +
<br>In the '''Maximum Number of Generations''' field, enter the desired maximum number of generations.
 +
<br>In the '''Minimal Number of Generations''' field, enter the desired minimal number of generations.
 +
<br>
 +
<div style="background-color: #E3FBE5;">Note: the above fields are grayed out if “Set Population Size” box is not checked in Basic Genetic Algorithm Parameters.</div>
 +
:20. If '''Proximal Convergence''' was selected, enter the desired convergence rate into the respective field. A value, approaching 1 is usually selected for the convergence rate; the default value is 0.99.
 +
:21. In the '''Genetic Algorithm Subtype''' section, select '''Basic''' or '''Incremental''' algorithm subtype. 
 +
:22. If Basic algorithm subtype was selected, select '''Yes''' or '''No''' for '''Use Elitism''' option.
 +
:23. If Incremental algorithm subtype was selected, select the '''Replacement Scheme''' between Worst, Parent and Random.
 +
:24. Click '''Optimize''' N '''combinations''' to run the optimization and generate the Optimization Report.
 +
:25. Optimization dialogue window shows Average fitness value for current population during optimization.
  
# Open the '''Format Objects''' window.<br><span>{{FormatObjectIS}}</span>
 
# Select the '''Signals''' tab.
 
# Click the '''Optimize''' button.
 
# In the '''Select Optimization Method''' dialog box that appears, select '''Genetic Algorithm'''.
 
# In the '''Genetic Algorithm Properties''' window that opens, select the '''Optimizable Inputs''' tab.
 
# Check/uncheck the check box to the left of the signal name and input name to enable/disable optimization for this input or check the check box to the left of the '''Signal Name''' column heading to enable optimization for all inputs (at least one input should be selected to perform optimization).
 
# The '''Current Value''' column shows input values that are currently selected for the signals applied on the chart.
 
# In the '''Start Value''' column, enter the desired starting values for each of the inputs.
 
# In the '''End Value''' column, enter the desired ending values for each of the inputs.
 
# In the '''Step''' column, enter the desired step size, for each of the inputs.
 
# The '''Step Count''' column shows current amount of steps for an input.
 
# Select the '''Algorithm-specific Properties''' tab.
 
# Select criteria:
 
#: 1. Select '''Standard Criteria'''.
 
#: 2. Select the criteria from the drop-down list. [[Performing_Optimization#Standard Criteria|Read more about Standard Criteria]].<br>or:<br>
 
#: 1. Select '''Custom Criteria'''.
 
#: 2. Click '''Edit...''' button.
 
#: 3. Write the script for the custom criteria. [[Performing_Optimization#Custom Criteria|Read more about Custom Criteria]].
 
#: 4. Click '''OK'''.
 
# Select '''Ascending''' or '''Descending''' option to sort the output in ascending or descending order, respectively.
 
# An optimum population size value is automatically placed into the '''Population Size''' box; if a different value is desired, enter the value into the box.
 
# In the '''Crossover Probability''' box, enter the desired crossover probability; value range is 0.95-0.99, with a default of 0.95.
 
# In the '''Mutation Probability''' box, enter the desired mutation probability; value range is 0.01-0.05, with a default of 0.05.
 
# In the '''Convergence Type''' drop-down list, select '''Number of Generations''' or '''Proximal Convergence'''.
 
# In the '''Maximum Number of Generations''' box, enter the desired maximum number of generations.
 
# If Proximal Convergence was selected, enter the desired minimum number of generations and convergence rate into the respective boxes. A value, approaching 1 is usually selected for the convergence rate; the default value is 0.990000.
 
# In the '''Genetic Algorithm Subtype''' drop-down list, select '''Basic''' or '''Incremental''' algorithm subtype. 
 
# If Basic algorithm subtype was selected, select '''Yes''' or '''No''' for '''Use Elitism''' option.
 
# If Incremental algorithm subtype was selected, select the '''Replacement Scheme''' and '''Offspring Number''' (number of “children”).
 
# Click '''OK''' to run the optimization and generate the Optimization Report.
 
# Optimization dialogue window shows Average fitness value for current population during optimization.
 
 
<br>
 
<br>
 
<div style="background-color: #E3FBE5;">Since '''MultiCharts 10''' that is possible to start optimization from '''Chart Analysis''' toolbar (see [[MultiCharts_Work_Area#Hiding_and_Redisplaying_Toolbars]]) by clicking on the '''Optimize Strategy''' button: [[File:toolbar2_ChartAn_125.png]]</div>
 
<div style="background-color: #E3FBE5;">Since '''MultiCharts 10''' that is possible to start optimization from '''Chart Analysis''' toolbar (see [[MultiCharts_Work_Area#Hiding_and_Redisplaying_Toolbars]]) by clicking on the '''Optimize Strategy''' button: [[File:toolbar2_ChartAn_125.png]]</div>
 
== Standard Criteria ==
 
Standard Criteria lets the user select a criterion from a pre-defined list.
 
 
For example, if the user selects Net Profit, the optimization will find the parameters that generate the highest Net Profit.
 
  
 
<br>
 
<br>
 
== Custom Criteria ==
 
== Custom Criteria ==
 
+
There are two types of criteria: standard and custom.
Custom Criteria lets the user create his own criteria.  Instead of choosing from a pre-defined list like in [[Performing_Optimization#Standard Criteria|Standard Criteria]], the user can script his own criteria. E.g., suppose the user wants to find the parameters that maximize the Net Profit / Max Drawdown ratio. This ratio isn't pre-defined under [[Performing_Optimization#Standard Criteria|Standard Criteria]], so it won't be in the drop-down list. However, this ratio can be created using Custom Criteria.
+
<br>Standard Criteria lets the user select a criterion from a pre-defined list. For example, if the user selects Net Profit, the optimization will find the parameters that generate the highest Net Profit.
 +
<br>Custom Criteria lets the user create his own criteria.  Instead of choosing from a pre-defined list like in Standard Criteria, the user can script his own criteria. E.g., suppose the user wants to find the parameters that maximize the Net Profit / Max Drawdown ratio. This ratio isn't pre-defined under Standard Criteria, so it won't be in the drop-down list. However, this ratio can be created using Custom Criteria.
  
 
It is also possible to add additional criteria such as number of trades and winning percentage.  
 
It is also possible to add additional criteria such as number of trades and winning percentage.  
Line 126: Line 124:
 
|align="center"|Yes
 
|align="center"|Yes
 
|-
 
|-
|Gross Loss
+
|GrossLoss
 
|Gross Loss
 
|Gross Loss
 
|align="center"|Yes
 
|align="center"|Yes
Line 136: Line 134:
 
|align="center"|Yes
 
|align="center"|Yes
 
|-
 
|-
|Percent Profitable
+
|PercentProfitable
 
|% Profitable
 
|% Profitable
 
|align="center"|Yes
 
|align="center"|Yes
 
|align="center"|Yes
 
|align="center"|Yes
 
|-
 
|-
|Winning Trades
+
|WinningTrades
 
|Winning Trades
 
|Winning Trades
 
|align="center"|Yes
 
|align="center"|Yes
Line 205: Line 203:
 
|align="center"|Yes
 
|align="center"|Yes
 
|align="center"|No
 
|align="center"|No
 +
|-
 +
|CustomFithessValue
 +
|Last [[SetCustomFitnessValue|SetCustomFitnessValue()]] calculation result.
 +
Will return 0 if [[SetCustomFitnessValue|SetCustomFitnessValue()]] was not calculated.
 +
|align="center"|Yes
 +
|align="center"|Yes
 
|}
 
|}
 +
<br>
 +
 +
== Pausing optimization ==
 +
 +
Since '''MultiCharts 10''' that is possible to pause the optimization process in order to temporary decrease the load on the CPU. To pause optimization click '''Pause''' in the '''Optimization Progress''' window. To resume optimization click '''Resume'''.
  
 
<br>
 
<br>
  
 
[[Category:Optimization]]
 
[[Category:Optimization]]

Latest revision as of 10:15, 23 February 2022

Once a strategy has been applied to a chart, strategy optimization can be performed.


Running Exhaustive Search

Optimization is performed from the Format Objects window:

To perform Exhaustive Search optimization:

1. Open the Format Objects window.

To open the Format Objects window, right-click on an empty area of the chart and then click Format Signals.

The Format Objects window can also be opened by one of the following methods:
  - Select Format in the main menu and click Signal.
  - Double-click any one of the signal's labels on the chart.
  - Position the mouse pointer over any one of the signal's labels on the chart; once the Pointer Pointer.png changes into a Hand Hand.png, right-click the label and then click Format Signals.

2. Select the Signals tab.
3. Click the Optimize button.
4. In the Choose the Optimization Type dialog box that appears, select Regular Optimization and click Next.
5. In the Set Optimizable Inputs section check/uncheck the check box to the left of the signal name and input name to enable/disable optimization for this input or check the check box to the left of the Signal Name column heading to enable optimization for all inputs (at least one input should be selected to perform optimization).
6. The Current Value column shows input values that are currently selected for the signals applied on the chart.
7. In the Start Value column, enter the desired starting values for each of the inputs.
8. In the End Value column, enter the desired ending values for each of the inputs.
9. In the Step column, enter the desired step size, for each of the inputs.
10. The Step Count column shows current number of steps for an input.
11. Select Exhaustive radio button in the Set Optimization Method section.
12. Select the target function to be optimized in Optimize by section:

In the Maximal/Minimal list, set the respective values to be selected at the end of optimization. From the next list one can select the function itself.
If Custom Criteria is selected, Edit button is available. Press it to write the script for the custom criteria. Read more about Standard and Custom Criteria.
In order to apply the desired function from code select Custom Fitness Value. The custom value shall be specified by SetCustomFitnessValue keyword in the script.

13. Select the Use Limitation checkbox to limit the output to a defined number of the best results; unselect the checkbox to list all the results in the optimization report.
14. When Use Limitation checkbox is checked Optimization dialog window shows current best results for selected сriteria during optimization.
15. Click Optimize N combinations to run the optimization and generate the Optimization Report.


Since MultiCharts 10 that is possible to start optimization from Chart Analysis toolbar (see MultiCharts_Work_Area#Hiding_and_Redisplaying_Toolbars) by clicking on the Optimize Strategy button: Toolbar2 ChartAn 125.png


Running Genetic Algorithm Search

Note: For detailed information on Genetic Algorithm properties, see Understanding Genetic Algorithm Optimization

Optimization is performed from the Format Objects window:

To perform Genetic Algorithm optimization:

1. Open the Format Objects window.

To open the Format Objects window, right-click on an empty area of the chart and then click Format Signals.

The Format Objects window can also be opened by one of the following methods:
  - Select Format in the main menu and click Signal.
  - Double-click any one of the signal's labels on the chart.
  - Position the mouse pointer over any one of the signal's labels on the chart; once the Pointer Pointer.png changes into a Hand Hand.png, right-click the label and then click Format Signals.

2. Select the Signals tab.
3. Click the Optimize button.
4. In the Choose the Optimization Type dialog box that appears, select Regular Optimization and click Next.
5. In the Set Optimizable Inputs section check/uncheck the check box to the left of the signal name and input name to enable/disable optimization for this input or check the check box to the left of the Signal Name column heading to enable optimization for all inputs (at least one input should be selected to perform optimization).
6. The Current Value column shows input values that are currently selected for the signals applied on the chart.
7. In the Start Value column, enter the desired starting values for each of the inputs.
8. In the End Value column, enter the desired ending values for each of the inputs.
9. In the Step column, enter the desired step size, for each of the inputs.
10. The Step Count column shows current number of steps for an input.
11. Select Genetic radio button in the Set Optimization Method section.
12. Selecting the target function to be optimized in the Optimize by: section:

In the Maximal/Minimal list, set the respective individuals, which will take part in further selection and crossover, for the selected parameter. From the next list one can select the function itself.
If Custom Criteria is selected, Edit button is available. Press it to write the script for the custom criteria. Read more about Standard and Custom Criteria.
In order to apply the desired function from code select Custom Fitness Value. The custom value shall be specified by SetCustomFitnessValue keyword in the script.

13. Set Basic Genetic Algorithm Parameters.
14. An optimum population size value is automatically placed next to the Set Population Size box; if a different value is desired, check Set Population Size box and select the value.
15. In the Crossover Probability field, select the desired crossover probability; value range is 0-1, with a default of 0.95.
16. In the Mutation Probability field, select the desired mutation probability; value range is 0-1, with a default of 0.05.
17. In the Convergence Type section, select Number of Generations or Proximal Convergence.
18. If Number of Generations is selected:

In the Number of Individuals in Population for Crossover field, enter the desired number of individuals in population for crossover.
In the Maximum Number of Generations field, enter the desired maximum number of generations.

Note: the above fields are grayed out if “Set Population Size” box is not checked in Basic Genetic Algorithm Parameters.
19. If Proximal Convergence is selected:

In the Number of Individuals in Population for Crossover field, enter the desired number of individuals in population for crossover.
In the Maximum Number of Generations field, enter the desired maximum number of generations.
In the Minimal Number of Generations field, enter the desired minimal number of generations.

Note: the above fields are grayed out if “Set Population Size” box is not checked in Basic Genetic Algorithm Parameters.
20. If Proximal Convergence was selected, enter the desired convergence rate into the respective field. A value, approaching 1 is usually selected for the convergence rate; the default value is 0.99.
21. In the Genetic Algorithm Subtype section, select Basic or Incremental algorithm subtype.
22. If Basic algorithm subtype was selected, select Yes or No for Use Elitism option.
23. If Incremental algorithm subtype was selected, select the Replacement Scheme between Worst, Parent and Random.
24. Click Optimize N combinations to run the optimization and generate the Optimization Report.
25. Optimization dialogue window shows Average fitness value for current population during optimization.


Since MultiCharts 10 that is possible to start optimization from Chart Analysis toolbar (see MultiCharts_Work_Area#Hiding_and_Redisplaying_Toolbars) by clicking on the Optimize Strategy button: Toolbar2 ChartAn 125.png


Custom Criteria

There are two types of criteria: standard and custom.
Standard Criteria lets the user select a criterion from a pre-defined list. For example, if the user selects Net Profit, the optimization will find the parameters that generate the highest Net Profit.
Custom Criteria lets the user create his own criteria. Instead of choosing from a pre-defined list like in Standard Criteria, the user can script his own criteria. E.g., suppose the user wants to find the parameters that maximize the Net Profit / Max Drawdown ratio. This ratio isn't pre-defined under Standard Criteria, so it won't be in the drop-down list. However, this ratio can be created using Custom Criteria.

It is also possible to add additional criteria such as number of trades and winning percentage.

E.g., it is possible to specify: the result have more than 300 trades and a winning percentage that's greater than 50%.


The scripting language is JavaScript.


Code Example

The code below creates the Net Profit / Max Drawdown ratio:

      
if (StrategyPerformance.MaxStrategyDrawDown != 0)       
{       
return StrategyPerformance.NetProfit / (-      
StrategyPerformance.MaxStrategyDrawDown);       
}


Besides NetProfit and MaxStrategyDrawdown, there are many other properties that can be referenced. The table below shows the available properties.
For example, to reference the number of trades, simply use StrategyPerformance.TotalTrades. To reference winning percentage, simply use StrategyPerformance.PercentProfitable.

Name of property in the object StrategyPerformance Description Available in MultiCharts Available in Portfolio Optimization
NetProfit Net Profit Yes Yes
GrossProfit Gross Profit Yes Yes
GrossLoss Gross Loss Yes Yes
TotalTrades Total Trades Yes Yes
PercentProfitable % Profitable Yes Yes
WinningTrades Winning Trades Yes Yes
LosingTrades Losing Trades Yes Yes
AvgTrade Avg Trade Yes No
AvgWinningTrade Avg Winning Trade Yes No
AvgLosingTrade Avg Losing Trade Yes No
WinLossRatio Win/Loss Ratio Yes No
MaxConsecWinners Max Consecutive Winners Yes No
MaxConsecLosers Max Consecutive Losers Yes No
AvgBarsInWinningTrades Avg Bars in Winner Yes No
AvgBarsInLosingTrades Avg Bars in Loser Yes No
MaxStrategyDrawDown Max Intraday Drawdown Yes Yes
ProfitFactor Profit Factor Yes No
ReturnOnAccount Return on Account Yes No
CustomFithessValue Last SetCustomFitnessValue() calculation result.

Will return 0 if SetCustomFitnessValue() was not calculated.

Yes Yes


Pausing optimization

Since MultiCharts 10 that is possible to pause the optimization process in order to temporary decrease the load on the CPU. To pause optimization click Pause in the Optimization Progress window. To resume optimization click Resume.