Operations > Strategy Analyzer > Optimize a Strategy >

Genetic Algorithm

Print this Topic Previous pageReturn to chapter overviewNext page

Genetic algorithm (GA) is another optimization technique that can be used to optimize your NinjaScript strategy parameters with. The Default optimization algorithm tests every single combination of parameters within the optimization range to find the best result possible, but since it is testing every combination possible, this requires a lot of computing power and time to complete. The GA can be more suited for these extensive optimizations because it is able to approximate best solutions without testing every combination through the evolutionary theory borrowed from biology.

 

tog_minusUnderstanding the Genetic Algorithm

Overview

The general idea of how the GA solves an optimization problem is analogous to the concept of how evolution via natural selection adapts a species to the environment. In biology, only the strongest individuals will be able to reproduce and pass on their superior genes to the next generation. Assuming each generation can only pass on the strongest genes, after several iterations we would be left with the optimal attributes for the environment. Through this same mechanism, the GA will test a random preset of your parameters. Through multiple generations of testing, the parameters will zero in on an optimum solution.

 

Note: It is important to understand that GA will find approximate optimum solutions. Since it does not test every combination possible there is no guarantee its solutions are absolute optimums.

 

How the GA calculates

The GA determines its solution through the following steps:

 

1.Begin with an initial population size consisting of randomly selected individuals (parameter setting combinations)
2.Compute the fitness (Optimize on...) for each individual in the population and assign probabilities to the population based on the fitness results. More fit results have more probability in being selected for breeding of the next generation.
3.Generate a new population for the next generation by selecting individuals from the prior generation to produce offspring via crossover and mutation (see below)
4.Repeat from step 2 till you reach the number of generations in your test

 

Crossover and Mutation

Crossover is the process in generating offspring that are not 100% identical to their parents. It is done by taking half of the parameter settings from parent A and mixing it with the other half from parent B. Crossover allows GA to test different combinations of parameters and hone in on the optimal solution. Crossover alone however will eventually yield identical offsprings in the population through several generations and so through mutation, some random parameter settings will be interjected in a few of the offsprings to allow for an adaptive quality to the algorithm.

tog_minusHow to run a Genetic optimization

Please see the "Optimize a Strategy" article for how to run an optimization.

 

When you select the Genetic optimizer you will see the following optimization properties:

 

Genetic_Algorithm_1

 

GO: # of Generations

Sets the number of generations to test

GO: Crossover Rate (%)

Each new generation is created from a combination of randomly generated offspring and offspring created from combining (crossing over) parent parameters. Crossover Rate determines the percentage of the new generation that is generated from the crossover process.

GO: Generation Size

Sets the number of combinations to test in each generation. The higher the size, the more variety of combinations to test.

GO: Minimum Performance

If this performance value is reached before all generations are evaluated the optimizer will end and present results immediately. Value of 0 means no minimum performance is in use.

GO: Mutation Rate (%)

Sets the probability that a crossover offspring will contain some mutated parameters

GO: Mutation Strength (%)

Sets the maximum offset from crossover values that an offspring marked for mutation can have its parameters changed

GO: Reset Size (%)

When each new generation is created, all individuals from previous generations are possible parents for the new offsprings. If the top performing x% (stability size %) of individuals from the newly created generation is the same as the top performing x% of parents, reset all parents and repopulate a new generation randomly while leaving only the top performing y% of parents (reset size %) for future generations.

GO: Stability Size (%)

See "GO: Reset Size %"

Keep best # results

Sets the number of best results to display

Optimize data series

If set to true, the Data Series Value property will be available for optimization (Not supported for Kagi, PointAndFigure, and Line Break period Types)

Optimize on...

Sets the optimization criterion to base the optimization results on. This is the "fitness function" for the GA.

Optimizer

Sets the optimization algorithm that is used. NinjaTrader comes with "Default" and "Genetic" optimizer algorithms.