Dhruv Toshniwal

Genetic Algorithm for Financial Portfolio Optimization

July 2023

Genetic Algorithm for Financial Portfolio Optimization

The Importance

Managing a portfolio of stocks is challenging in volatile financial markets. Traditional methods like Modern Portfolio Theory focus on diversification, but struggle with predicting returns and variances.

Genetic Algorithms (GAs) offer an innovative solution. These evolutionary algorithms use biological-inspired mechanisms like reproduction, mutation, and selection to solve complex optimization problems.

The Approach

The project uses a Python-based approach to optimize a portfolio of fintech stocks, aiming to maximize the Sharpe Ratio. The strategy employs a Moving Average Crossover method:

  • Uses stocks from companies like Visa, Mastercard, and PayPal
  • Generates buy/sell signals when short-term moving averages cross long-term moving averages
  • Genetic Algorithm finds optimal window sizes for moving averages

The Code

Key technical components:

  • Used 'yfinance' to fetch historical stock data
  • Implemented moving average crossover strategy
  • Utilized 'deap' package for evolutionary algorithm
  • Genetic Algorithm evolves solutions over multiple generations

The Result

The algorithm demonstrated progressive improvement in the Sharpe Ratio across generations. The project serves as a foundation for exploring more complex trading strategies and portfolio optimization techniques.

View Project on GitHub