Strategy Optimization, Curve Fitting and Walk Forward Analysis.: Walk-Forward Optimization Simple example
Simple example of WFO.
Genetic Optimizer is used as optimizator.
Walk-Forward Optimization is demonstrated in this example on simple strategy that consists of moving averages and stop-loss exits.
Entry parameters:
SampleStart - Number of bar when segment Sample begins.
SampleLen - Length of Sample segment.
OOSLen - Length of Out of Sample segment (OOS).
Gen - Number of iterations for Genetic optmizer.
MYStrategyName - Name of strategy that is used for saving current population.
In order to perform WFO it's necessary to optimization parameters in certain way.
To do it you need to set optimization in TradeStation for parameter SampleStart from 1 to number of bars K with step that is equal to length of OOS segment.
SampleLen should exeed length of OOS several times. Also we set optimization on parameter Gen from 1 to M with step 1.
K - should be more than SampleLen + OOSLen + Max number of bars strategy will reference
M - should be more than size of population - in this example size of population = 50.
Example of setting parameters:
SampleStart = 1..1400:20
SampleLen = 200.
OOSLen = 20
Gen = 1..100:1
MyStrategyName = “WFO_Test”
Work of trading Strategy.
For every value of SampleStart cycle of optimization is performed Gen = 1..100:1.
Results of optimization for every value of SampleStart are exported into window using Print.
Results.
On picture below results of testing are showen using parameter above. Test of the strategy with WFO.

Picture 1. Results of WFO using Genetic Optimizer for TradeStation.
Table contains WFO results that are exported using
| EasyLanguage: | print( TS.GO.Get("Sample.Start" ,1), TS.GO.Get("Sample.End" ,1), TS.GO.Get("OOS.Start" ,1), TS.GO.Get("OOS.End" ,1), TS.GO.Get("Sample.Fitness" ,1), TS.GO.Get("OOS.Fitness" ,1), TS.GO.Get("Sample.Profit" ,1), TS.GO.Get("OOS.Profit" ,1), TS.GO.Get("Len1" ,1), TS.GO.Get("Len2" ,1), TS.GO.Get("Len3" ,1), TS.GO.Get("Len4" ,1), TS.GO.Get("SL" ,1) )
|
column A contains Sample.Start
column B contains Sample.End
and etc.
Everly line contains data one optimizatio window.
For example first line:
Sample with 1 on 100 bar,
OOS with 101 on 120 bars,
Sample.Fitness = 0
There is acumulated profit by segments OOS shown on first picture.
Profit on Sample area is placed on X axis and profit on Y axis on second picture.
|