Training variables

TrainMode

Training method; affects the way how parameters, factors, rules, or machine learning models are generated in the training process. The following flags can be set:

Flags:

ASCENT Ascent parameter optimization and parameter chart export. Evaluates the effect of any parameter on the strategy separately. Starts with the first parameter and applies the results of already optimized parameters and the defaults of the rest. Seeks for 'plateaus' in the parameter space, while ignoring single peaks. This is normally the best algorithm for a robust strategy, except in special cases with highly irregular parameter spaces or with interdependent parameters.
BRUTE Brute force parameter optimization and parameter spreadheet export (Zorro S required). Evaluates all parameter combinations, exports them to a *par.csv  file in the Log folder, and selects the most profitable combination that is not a single peak. Can take a long time when many parameters are optimized or when parameter ranges have many steps. Useful when parameters affect each other in complex ways, or when it is necessary to evaluate results from any parameter combination. Brute force optimization tends to overfit the strategy, so out-of-sample testing or walk-forward optimization is mandatory.
GENETIC Genetic parameter optimization (Zorro S required). A population of parameter combinations is evolved toward the best solution in an iterative process. In each iteration, the best combinations are stochastically selected, and their parameters are then pair-wise recombined and randomly mutated to form a new generation. This algorithm is useful when a large number of parameters - 5 or more per component - must be optimized, or when parameters affect each other in complex ways. It will likely overfit the strategy, so out-of-sample or walk-forward testing is mandatory.
TRADES Use trade sizes by Lots, Margin, etc. Large trades get then more weight in the optimization process. Set this flag in special cases when the trade volume matters, f.i. for optimizing the money management or for portfolio systems that calculate their capital distribution by script. Otherwise trade sizes are ignored in the training process for giving all trades equal weights.
PHANTOM Exclude phantom trades. Otherwise phantom trades are treated as normal trades in the training process.
PEAK Optimize toward the highest single peak in the parameter space, rather than toward hills or plateaus. This can generate unstable strategies and is for special purposes only. For instance when optimizing not a parameter range, but a set of different algorithms or different assets.
ALLCYCLES Generate individual OptimalF factor files for all WFO cycles, instead of a single file for the whole simulation. This produces low-quality factors due to less trades, but prevents backtest bias.

NumParameters

Number of parameters to optimize for the current asset/algo component that was selected in a loop (int, read/only, valid after the first INITRUN).

ParCycle

Current parameter or current generation, runs from 1 to NumParameters in Ascent mode, or from 1 to Generations in Genetic mode (int, read/only, valid after the first INITRUN).

StepCycle

Number of the optimize step, starting with 1 (int, read/only, valid after the first INITRUN). The number of step cycles depends on the number of steps in a parameter range and of the population in a genetic optimization. Counts up after any step until the required number is reached or StepNext is set to 0. 

StepNext

Set this to 0 for early aborting the optimization (int).

NumTrainCycles

Number of training cycles (int, default = 1) for special purposes, such as training a combination of interdependent rules and parameters in a given order (see Training). In any cycle, set either RULES, or PARAMETERS, or both, dependent on training method. Not to be confused with WFO cycles or Generations.

TrainCycle

The number of the current training cycle from 1 to NumTrainCycles, or 0 in [Test] or [Trade] mode (int, read/only). The training mode of the current cycle can be determined with the PARCYCLE, RULCYCLE, FACCYLE flags.

LogTrainRun

Set this to a identifier number for logging a particular training run. The identifier is a 5-digit number in the format WFSPO, where W = WFO cycle, F = first loop iteration, S = second loop iteration, P = parameter number, and O = optimize step. At 11111 the very first training run is logged. 

Population

Maximum population size for the genetic algorithm (int, default = 50). Any parameter combination is an individual of the population. The population size reduces automatically when the algorithm converges and only the fittest individuals and the mutants remain.

Generations

Maximum number of generations for the genetic algorithm (int, default = 50). Evolution terminates when this number is reached or when the overall fitness does not increase for 10 generations.

MutationRate

Average number of mutants in any generation, in percent (int, default = 5%). More mutants can find more and better parameter combinations, but let the algorithm converge slower.

CrossoverRate

Average number of parameter recombinations in any generation, in percent (int, default = 80%). 

BestResult

Highest objective return value so far (var, starting with 0).

Parameters

Pointer to a list of PARAMETER structs for the current asset/algo component. The Min, Max, and Step elements are set up in the list after the first INITRUN in [Train] mode. The PARAMETER struct is defined in trading.h.

Remarks:

Example:

setf(TrainMode,TRADES+PEAK);

See also:

Training, optimize, advise, OptimalF, objective, setf, resf
► latest version online