NumWFOCycles

Number of cycles in a Walk Forward Optimization / Analysis (default = 0 = no Walk Forward Optimization). If NumWFOCycles is set to a positive number, rolling walk forward optimization is enabled with the given number of cycles; if it is set to a negative number, anchored walk forward optimization is enabled. In Walk Forward Optimization, a data frame consisting of a training and test period is shifted over the simulation period in the given number of cycles (see image).

WFOCycle
Simulation period
1
LookBack
Training
Test1
2
LookBack
Training
Test2
3
LookBack
Training
Test3
4
LookBack
Training
Test4
5
 
LookBack
Training
OOS Test
LookBack
Test5
WFO Test
Look
Back
Test1
Test2
Test3
Test4
Rolling Walk Forward Optimization (NumWFOCycles > 0)
 
WFOCycle
Simulation period
1
LookBack
Training
Test1
2
LookBack
Training
Test2
3
LookBack
Training
Test3
4
LookBack
Training
Test4
5
LookBack
Training
WFO Test
Look
Back
Test1
Test2
Test3
Test4
Anchored Walk Forward Optimization (NumWFOCycles < 0)

Strategy parameters and trade rules are generated separately for every cycle in [Train] mode, and are separately loaded for every test segment in [Test] mode. This way, the strategy test is guaranteed to be out of sample - it uses only parameters and rules that were generated in the preceding training cycle from data that does not occur in the test. This simulates the behavior of real trading where parameters and rules are generated from past price data. A Walk Forward Test gives the best prediction possible of the strategy performance over time.

WFOPeriod

Alternative to NumWFOCycles; number of bars of one WFO cycle consisting of training + test. If a fixed test period of T bars is given, WFOPeriod is T*DataSplit/(100-DataSplit).

WFOCycle

The number of the current WFO cycle, from 1 to NumWFOCycles. Read/only; automatically set during WFO test and training.

WFOBar

The bar number inside the current WFO cycle, starting with 0 at the begin of the cycle. Can be used to determine when the cycle starts: if(WFOBar == 0). Read/only; automatically set during WFO test.

SelectWFO

Set this to a certain WFO cycle number for selecting only this cycle in a training or test; otherwise the process runs over all cycles. A negative number selects the cycle from the end, f.i. -1 selects the last cycle for an OOS Test.

Type:

int

Remarks:

Examples:

function run()
{
  NumWFOCycles = -10; // anchored WFO, 10 cycles 
  DataSplit = 80; // 20% test cycle
  DataSlope = 2;  // more weight to more recent data
  set(PARAMETERS+TESTNOW); // run a test immediately after WFO
  ...
}

// calculate NumWFOCycles from the test period in days
// DataSplit and LookBack must be set before
function setWFO2(int daysTest)
{
asset(Asset); // requires NumBars, so asset must be set
int barsTest = daysTest * 1440/BarPeriod;
int barsTrain = barsTest * DataSplit/(100-DataSplit);
int barsTotal = NumBars-LookBack;
NumWFOCycles = (barsTotal-barsTrain)/barsTest + 1;
}

See also:

Training, Tutorial, DataSplit, NumSampleCycles, NumTotalCycles, NumOptCycles

 

► latest version online