Skip to content

Mehtab161/Portfolio-Optimization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

📊 Portfolio Optimization using LSTM & Modern Portfolio Theory

🚀 Overview

This project combines Deep Learning (LSTM) with Modern Portfolio Theory (MPT) to build an intelligent portfolio optimization system. It predicts future stock returns using time-series forecasting and optimizes asset allocation to maximize returns while analyzing risk.

🎯 Objectives

  • Predict stock returns using LSTM (Deep Learning)
  • Apply Modern Portfolio Theory (MPT) for optimization
  • Maximize Sharpe Ratio (risk-adjusted return)
  • Analyze risk vs return trade-offs

🧠 Tech Stack

  • Python
  • NumPy, Pandas
  • Matplotlib, Seaborn
  • yFinance
  • TensorFlow / Keras (LSTM)
  • SciPy (SLSQP Optimization)

📂 Dataset

  • Historical stock data of 10 companies
  • Time period: 2020 – Present (~5+ years)
  • Source: Yahoo Finance (yfinance)

⚙️ Methodology

Data Collection & Preprocessing

  • Collected stock data using yfinance
  • Calculated log returns
  • Applied MinMax Scaling
  • Split into 80% training / 20% testing

LSTM Model (Time-Series Forecasting)

  • Built 2-layer LSTM (100 units each)
  • Used 30-day look-back window
  • Predicted future stock returns

Portfolio Optimization

  • Calculated Expected Return, Volatility, Sharpe Ratio
  • Used SciPy SLSQP optimization
  • Constraints: weights sum = 1, no short selling

📈 Results

Markowitz Optimization

  • Expected Return: 13.45%
  • Volatility: 20.44%
  • Sharpe Ratio: 0.61

LSTM-Based Optimization

  • Expected Return: 53.43%
  • Risk: 130.99%

ML-based approach increases return potential but also significantly increases risk.

▶️ How to Use

1. Clone the Repository

git clone https://github.com/Mehtab161/Portfolio-Optimization.git cd portfolio-optimization

2. Install Dependencies

pip install numpy pandas matplotlib seaborn yfinance scikit-learn tensorflow scipy plotly

3. Run the Project

jupyter notebook

Open and run: PortfolioOptimizationFinal.ipynb

⚙️ Customize Inputs

  • Modify stock list in code
  • Change date range
  • Adjust LSTM parameters (LOOK_BACK, FORECAST_RANGE)

📊 Output

  • Predicted returns using LSTM
  • Optimal portfolio weights
  • Expected return, volatility, Sharpe ratio
  • Visualizations of trends and allocations

📌 Key Learnings

  • Time-series forecasting using LSTM
  • Portfolio optimization using MPT
  • Understanding risk-return trade-offs
  • Combining ML with finance concepts

🔗 Future Improvements

  • Add more stocks for diversification
  • Use advanced models (GRU, Transformers)
  • Add backtesting for validation
  • Deploy as a web application

🤝 Connect


⭐ Don’t forget to star the repo if you like it!

About

LSTM-based portfolio optimization using Modern Portfolio Theory to maximize returns and analyze risk-return trade-offs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors