Evolving Portfolio Weights: A Genetic Algorithm Approach to Mean Reversion

In my previous post, I examined various weighting strategies within the S&P 500’s top 20 stocks and illustrated the phenomenon of regression toward the mean in financial markets.

In this post, I take a different approach: applying a genetic algorithm (GA) to the same problem. The question is whether an evolutionary process — driven by selection, crossover, and mutation — will reveal similar patterns of convergence and mean reversion.

Genetic Algorithm 101

A genetic algorithm is inspired by natural selection. Populations evolve over generations, with fitter individuals more likely to reproduce. Through operators such as:

  • Selection → choosing parents based on fitness

  • Crossover → combining genes from parents

  • Mutation → introducing random variation

…the population gradually adapts toward better solutions.

Algorithm Setup

For this portfolio problem, the gene sequence is an array of weights for the top 20 S&P 500 stocks: {w1, w2, …, w20}, and the total weight should be 100.

The GA procedure is:

  1. Initialize a population with random weight setups.

  2. Evaluate fitness (annual return of each portfolio). Higher fitness increases reproduction probability.

  3. Generate offspring by selecting parents and applying crossover/mutation until the population size is restored.

  4. Replace population with offspring and repeat until the maximum generation is reached.

Crossover Approaches

I tested two crossover methods:

  1. Gene Blending → offspring genes are linear combinations of parent arrays.

  2. Gene Split → arrays are split in half and recombined from each parent.

Results: Gene Blending

  • Fitness distribution: Returns quickly converged to a narrow range with slightly higher median scores.

  • Top vs. bottom portfolios: Over generations, weights became increasingly even, reflecting a tendency toward balance.

Box plot showing fitness score distributions across generations using gene blending
Figure: Distribution of fitness scores across generations using gene blending crossover. The population quickly converges toward a narrow range of annual returns, with reduced variability and slightly improved median performance over time.



Animated GIF showing top 5 and bottom 5 portfolio weight distributions across generations using gene blending crossover, converging toward even allocations.
Figure: Evolution of weight distributions for the top 5 and bottom 5 portfolios across generations using gene blending crossover. Over time, the weights converge toward more even allocations, highlighting how evolutionary pressure smooths extremes in portfolio construction.

Results: Gene Splitting

  • Fitness distribution: Median scores rose steadily in early generations, then stabilized.

  • Variation: Wider distributions persisted, with more outliers than in gene blending.

  • Top vs. bottom portfolios: Less even than blending, but also no power law distribution like market cap, and retained strong traits across generations.


Box plot showing fitness score distributions across generations using gene split crossover, with increasing median values and wider variability.
Figure: Distribution of fitness scores across generations using gene split crossover. The median performance improves steadily in early generations and stabilizes later, but the wider spread and persistent outliers suggest greater diversity in portfolio outcomes compared to gene blending.


Animated GIF showing top 5 and bottom 5 portfolio weight distributions across generations using gene split crossover, with persistent diversity and uneven allocations.
Figure: Evolution of weight distributions for the top 5 and bottom 5 portfolios across generations using gene split crossover. Unlike gene blending, this method preserves more diversity in weight setups, with less convergence toward even allocations and more persistent variation across generations. However, there is also no power-law-like distribution in market capitalization weight.

This approach produced slightly better overall performance in later generations, though the weight setups are more complex than simple equal-weight strategies.

Comparing Portfolios

One of the best-performing GA portfolios in the final generation was compared against:

  • Top 10 Equal-Weight

  • Top 11–20 Equal-Weight

Line graph comparing Top 10 and Top 11–20 Equal-Weight portfolio performance from 1990 to 2023, showing boom-cycle strength vs. contraction-cycle resilience.
Figure: Performance comparison between Top 10 Equal-Weight and Top 11–20 Equal-Weight strategies. The Top 10 strategy excels during boom cycles (e.g., late 1990s, 2018–2020), while the 11–20 strategy shows greater resilience during contractions (e.g., 2002–2008). As illustrated in the graph, during the boom period, the GA weight matched that of the Top 10 Equal-Weight strategy; however, during the contraction period, it performed as well as the Top 11-20 Equal-Weight strategy. 

Key Observations

  • Boom cycles (late 1990s, 2018–2020): GA portfolio performed comparably to Top 10 Equal-Weight.

  • Contraction cycles (2002–2008): The GA portfolio showed resilience similar to Top 11–20 Equal-Weight.

  • Overall performance: Outperformed both equal-weight strategies by ~1.4–1.6% annually.

Over 35 years, this small advantage compounded dramatically (with initial investment: $100K in 1990):

  • GA portfolio: ~$4.3 million

  • Equal-weight portfolios: ~$2.6–2.8 million


Conclusion

Applying a genetic algorithm to portfolio weighting reveals how evolutionary processes can balance risk and reward.

  • Gene blending converges quickly but favors even distributions.

  • Gene splitting maintains diversity and captures stronger traits, leading to better long-term performance.

  • The GA portfolio demonstrates both boom-cycle upside and downside resilience, echoing the dynamics of regression toward the mean while compounding small advantages into significant gains.

While complex to implement in real-world scenarios, this experiment shows that evolutionary algorithms can uncover weighting strategies that outperform traditional equal-weight approaches — and highlight the subtle interplay between concentration, resilience, and mean reversion in financial markets.

Comments

Popular posts from this blog

When Missing Voices and Missing Winners Mislead: Rethinking Retrospective Studies