Using Genetic Algorithms to Forecast Financial Markets

Samantha (Sam) Silberstein, CFP®, CSLP®, EA, is an experienced financial consultant. She has a demonstrated history of working in both institutional and retail environments, from broker-dealers to RIAs. She is a current CFA level 3 candidate and also has her FINRA Series 7 and 63 licenses. Throughout her career, Samantha has used her expertise and various licenses and certifications to provide in-depth advice about household and business-specific financial planning, investing, credit cards, debt, student loans, taxes, retirement, and income strategies.

In "A Random Walk Down Wall Street" (1973), Burton Malkiel suggested, "A blindfolded monkey throwing darts at a newspaper's financial pages could select a portfolio that would do just as well as one carefully selected by experts." While evolution may have made man no more intelligent at picking stocks, Charles Darwin's theory has proven to be effective when applied more directly.

Genetic algorithms are unique ways to solve complex problems by harnessing the power of nature. By applying these methods to predicting security prices, traders can optimize trading rules by identifying the best values to use for each parameter for a given security.

Key Takeaways

What Are Genetic Algorithms?

Genetic algorithms (GAs) are problem-solving methods (or heuristics) that mimic the process of natural evolution. Unlike artificial neural networks (ANNs), designed to function like neurons in the brain, these algorithms utilize the concepts of natural selection to determine the best solution for a problem.

As a result, GAs are commonly used as optimizers that adjust parameters to minimize or maximize some feedback measure, which can then be used independently or in the construction of an ANN. (To learn more about ANNs, see: Neural Networks: Forecasting Profits.)

In the financial markets, genetic algorithms are most commonly used to find the best combination values of parameters in a trading rule, and they can be built into ANN models designed to pick stocks and identify trades.

How Genetic Algorithms Work

Genetic algorithms are created mathematically using vectors, which are quantities that have direction and magnitude. Parameters for each trading rule are represented with a one-dimensional vector that can be thought of as a chromosome in genetic terms. Meanwhile, the values used in each parameter can be thought of as genes, which are then modified using natural selection.

For example, a trading rule may involve the use of parameters like moving average convergence divergence (MACD), an exponential moving average (EMA) and stochastics. A genetic algorithm would then input values into these parameters with the goal of maximizing net profit. Over time, small changes are introduced, and those that make a desirable impact are retained for the next generation.

(See also: Basics of Algorithmic Trading.)

There are three types of genetic operations that can then be performed:

These three operations are then used in a five-step process:

  1. Initialize a random population, where each chromosome is n-length, with n being the number of parameters. That is, a random number of parameters are established with n elements each.
  2. Select the chromosomes, or parameters, that increase desirable results (presumably net profit).
  3. Apply mutation or crossover operators to the selected parents and generate an offspring.
  4. Recombine the offspring and the current population to form a new population with the selection operator.
  5. Repeat steps two to four.

Over time, this process will result in increasingly favorable chromosomes (or parameters) for use in a trading rule. The process is then terminated when stopping criteria are met, which can include running time, fitness, number of generations or other criteria.

Using Genetic Algorithms in Trading

While genetic algorithms are primarily used by institutional quantitative traders, individual traders can harness the power of genetic algorithms—without a degree in advanced mathematics—using several software packages on the market.

These solutions range from standalone software packages geared toward the 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 that are then optimized using a genetic algorithm and a set of historical data. Some applications can optimize which parameters are used and the values for them, while others are primarily focused on simply optimizing the values for a given set of parameters.

Curve fitting (i.e. overfitting), or designing a trading system around historical data rather than identifying repeatable behavior, represents a potential risk for traders using genetic algorithms. Any trading system using GAs should be forward-tested on paper before live usage.

Choosing parameters is an important part of the process, and traders should seek out parameters that correlate to changes in the price of a given security. For example, try out different indicators to see if any seem to correlate with major market turns.

The Bottom Line

These algorithms are not the Holy Grail, and traders should be careful to choose the right parameters and not curve fit.