Optimizing Investment Portfolios with Machine Learning and Mean-Variance Analysis

Optimizing Investment Portfolios with Machine Learning and Mean-Variance Analysis

Investing has always been about balancing risk and reward. Whether you're managing a personal portfolio or overseeing millions in institutional investments, finding the right allocation of assets to maximize returns while minimizing risk is crucial. In this post, we’ll dive into how Machine Learning (ML) and Mean-Variance Optimization (MVO) can revolutionize portfolio management, using Dividend Kings as our investment universe.


Why Dividend Kings?

By default, the repository focuses on Dividend Kings—stocks that have increased dividends for at least 50 consecutive years. These companies are renowned for their financial stability, consistent returns, and shareholder-friendly policies. Dividend Kings offer a realistic and relatively conservative set of stocks for applying portfolio optimization techniques.

This choice ensures that the portfolio is built on reliable, historically strong performers while leaving room to explore the benefits of optimization. Of course, the code is flexible—you can specify any set of tickers if you prefer growth stocks, ETFs, or other instruments.

For more on Dividend Kings, check out the full list here: Dividend Kings List.


Introduction to Portfolio Optimization

At the heart of portfolio management lies the concept of the Efficient Frontier. This theoretical boundary identifies the optimal trade-off between portfolio risk (volatility) and return. Harry Markowitz's Mean-Variance Optimization (MVO) introduced a systematic approach to achieving this balance, and it remains one of the most influential financial models.

However, traditional methods rely heavily on historical data and fixed assumptions. Markets, on the other hand, are dynamic and complex. This is where Machine Learning enters the equation—by forecasting future returns and adjusting to changing conditions, ML models can augment MVO for better decision-making.


Blending Machine Learning with MVO

Our project combines the power of predictive modeling with the rigor of statistical optimization. By using ML models like Linear Regression, we estimate asset returns based on historical data and trends. These predicted returns are then fed into the MVO algorithm to calculate the optimal allocation of assets.

Key Features:

  • Black-Litterman Framework: Adjusts market returns based on investor views and confidence levels.
  • Efficient Frontier Analysis: Visualizes the best possible portfolios for various risk levels.
  • Performance Metrics: Includes Sharpe Ratio, Sortino Ratio, and Information Ratio to measure portfolio efficiency.

Portfolio Details

For this project, we used the following Dividend Kings as our investment universe:

SymbolCompany NameWeightSector
MOAltria Group Inc.4%Consumer Staples
NWNNorthwest Natural Gas14%Utilities
BKHBlack Hills Corp.1%Utilities
EDCon Edison1%Utilities
PEPPepsiCo Inc.9%Consumer Staples
NFGNational Fuel Gas16%Utilities
KOCoca-Cola Company6%Consumer Staples
FRTFederal Realty Inv. Trust28%Real Estate
GPCGenuine Parts Co.16%Consumer Discretionary
MSEXMiddlesex Water Co.5%Utilities

The total portfolio value is $100,000, with weights translating into dollar amounts. For instance, a 4% weight in MO means $4,000 invested in Altria Group.


How It Works

  1. Input Portfolio: Define the initial portfolio with weights and market caps.
  2. Predict Returns: Use Machine Learning models to predict future returns for each asset.
  3. Optimize Allocation: Use MVO to find the optimal weights for the portfolio based on predicted returns, minimizing risk while maximizing returns.
  4. Backtest: Simulate the optimized portfolio’s performance against historical data.
  5. Visualize Results: Generate the Efficient Frontier, plot portfolio performance, and compare with the benchmark (S&P 500).

Results

Our project provides several outputs to help investors make informed decisions:

  1. Efficient Frontier: A curve showing the best portfolios for different risk levels.
  2. Capital Market Line (CML): A line representing portfolios that combine the risk-free asset with the market portfolio.
  3. Performance Metrics:
    • Sharpe Ratio: How much return you earn for every unit of risk.
    • Sortino Ratio: Similar to Sharpe but focuses only on downside risk.
    • Information Ratio: Compares portfolio performance against a benchmark.

Below is a sample visualization generated by our project:


Why This Matters

  1. Customizable: Investors can adjust parameters like risk tolerance, minimum/maximum asset weights, and the choice of ML models.
  2. Adaptability: The use of ML ensures that the portfolio adapts to changing market conditions.
  3. Transparency: By visualizing the Efficient Frontier and other metrics, investors gain clarity on how decisions impact performance.

How to Get Started

Want to try it yourself? Here’s how:

  1. Clone the GitHub repository:

    git clone https://github.com/JordiCorbilla/machine-learning-optimization-portfolio.git
  2. Install dependencies:

    pip install -r requirements.txt
  3. Define your portfolio in the fetch_portfolio_data() method.
  4. Run the main() function:

    python portfolio_optimization.py

The outputs will include:

  • Optimized portfolio weights.
  • Performance metrics and tables.
  • Visualization of the Efficient Frontier and portfolio performance.

Conclusion

Combining Machine Learning with Mean-Variance Optimization bridges the gap between modern predictive analytics and traditional portfolio theory. By applying this to Dividend Kings, we focus on reliable, stable companies while exploring innovative techniques to maximize returns and minimize risks.


References

  1. Markowitz, H. (1952). Portfolio Selection. The Journal of Finance.
  2. Dividend Kings List

Disclaimer: This project is for educational purposes only and does not constitute financial advice. Always consult a financial advisor before making investment decisions.

Comments

Popular Posts