In “A Random Walk on Wall Street” (1973), Burton Malkiel suggested: “A blindfolded monkey throws a dart at the financial page of the newspaper, and it can choose the same as a portfolio carefully selected by an expert Excellent portfolio.” Although evolution may make humans no longer smart in stock picking, Charles Darwin’s theory has proven effective when applied more directly.

Genetic algorithm is a unique method to solve complex problems by using the power of nature. By applying these methods to predict security prices, traders can optimize trading rules by determining the best value for each parameter for a given security.

Key points

- Complex computer algorithms based on the rules of genetics and evolution have recently achieved some success in securities trading.
- By applying these methods to predict the price of securities, traders can optimize trading rules and create new strategies.
- Individual traders can use several software packages on the market to take advantage of the power of genetic algorithms.

What is genetic algorithm?

## What is genetic algorithm?

Genetic algorithm (GA) is a problem solving method (or heuristic) that simulates the natural evolution process. Unlike artificial neural networks (ANN), which are designed to function like neurons in the brain, these algorithms use the concept of natural selection to determine the best solution to a problem.

Therefore, GA is usually used as an optimizer to adjust parameters to minimize or maximize certain feedback metrics, and then can be used independently or in the construction of ANN. (To learn more about ANN, see: *Neural Network: Predicting Profit*.)

In the financial market, genetic algorithms are most commonly used to find the best combination of parameters in trading rules, and they can be built into ANN models designed to select stocks and identify transactions.

Several studies have proved the effectiveness of these methods, including “Genetic Algorithm: The Origin of Stock Evaluation” (2004) and “Application of Genetic Algorithm in Stock Market Data Mining Optimization” (2004). (For more information, see: *How to create a trading algorithm*.)

## How the genetic algorithm works

Genetic algorithms are created mathematically using vectors, which are quantities with directions and magnitudes. The parameters of each trading rule are represented by a one-dimensional vector, which can be regarded as a chromosome in terms of genetics. At the same time, the value used in each parameter can be considered as a gene, which can then be modified using natural selection.

For example, trading rules may involve the use of parameters such as moving average convergence divergence (MACD), exponential moving average (EMA), and stochastic indicators. The genetic algorithm will then enter values into these parameters to maximize net profit. Over time, some small changes will be introduced, and those changes that have the desired impact will be reserved for the next generation.

(Also take a look: *Fundamentals of Algorithmic Trading*.)

Three types of genetic operations can then be performed:

- Crossover represents reproduction and crossover seen in biology, whereby a child has certain characteristics of his parents.
- Mutation stands for biological mutation and is used to maintain genetic diversity from one generation to the next by introducing small random changes.
- Selection is the stage of selecting individual genomes from the population for later breeding (recombination or crossover).

Then these three operations are used in a five-step process:

- Initialize a random population, where each chromosome is
*n*-Length, and*n*Is the number of parameters.In other words, create a random number of parameters*n*Every element. - Choose chromosomes or parameters that increase the desired result (perhaps net profit).
- Apply mutation or crossover operator to selected parents and generate offspring.
- Use the selection operator to recombine the offspring and the current population to form a new population.
- Repeat steps 2 to 4.

Over time, this process will result in more and more favorable chromosomes (or parameters) for trading rules. The process will terminate when the stopping criteria are met, which include running time, fitness, algebra, or other criteria.

## Use genetic algorithms in trading

Although genetic algorithms are mainly used by institutional quantitative traders, individual traders can take advantage of the power of genetic algorithms—no advanced mathematics degree required—using several software packages on the market.

These solutions range from standalone software packages for financial markets to Microsoft Excel add-ons that can facilitate more hands-on analysis.

When using these applications, traders can define a set of parameters and then optimize them using genetic algorithms and a set of historical data. Some applications can optimize which parameters and their values are used, while other applications focus on simply optimizing the values of a given set of parameters.

Curve fitting (that is, overfitting) or designing a trading system around historical data instead of identifying repeatable behaviors is a potential risk for traders using genetic algorithms. Any trading system that uses GA should be prospectively tested on paper before actual use.

Selecting parameters is an important part of the process, and traders should look for parameters related to changes in the price of a given security. For example, try different indicators and see if any indicators seem to be related to the main market turn.

## Bottom line

These algorithms are not the Holy Grail, and traders should be careful to choose the correct parameters instead of curve fitting.

(For more reading, please check: *Choosing the right algorithmic trading software, the power of program trading, *and *How to write your own algorithmic trading robot*.)

.