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.
- 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
- Python
- NumPy, Pandas
- Matplotlib, Seaborn
- yFinance
- TensorFlow / Keras (LSTM)
- SciPy (SLSQP Optimization)
- Historical stock data of 10 companies
- Time period: 2020 – Present (~5+ years)
- Source: Yahoo Finance (yfinance)
- Collected stock data using yfinance
- Calculated log returns
- Applied MinMax Scaling
- Split into 80% training / 20% testing
- Built 2-layer LSTM (100 units each)
- Used 30-day look-back window
- Predicted future stock returns
- Calculated Expected Return, Volatility, Sharpe Ratio
- Used SciPy SLSQP optimization
- Constraints: weights sum = 1, no short selling
- Expected Return: 13.45%
- Volatility: 20.44%
- Sharpe Ratio: 0.61
- Expected Return: 53.43%
- Risk: 130.99%
ML-based approach increases return potential but also significantly increases risk.
git clone https://github.com/Mehtab161/Portfolio-Optimization.git cd portfolio-optimization
pip install numpy pandas matplotlib seaborn yfinance scikit-learn tensorflow scipy plotly
jupyter notebook
Open and run: PortfolioOptimizationFinal.ipynb
- Modify stock list in code
- Change date range
- Adjust LSTM parameters (LOOK_BACK, FORECAST_RANGE)
- Predicted returns using LSTM
- Optimal portfolio weights
- Expected return, volatility, Sharpe ratio
- Visualizations of trends and allocations
- Time-series forecasting using LSTM
- Portfolio optimization using MPT
- Understanding risk-return trade-offs
- Combining ML with finance concepts
- Add more stocks for diversification
- Use advanced models (GRU, Transformers)
- Add backtesting for validation
- Deploy as a web application
- LinkedIn: www.linkedin.com/in/mehtab-khan-mk
- GitHub: https://github.com/Mehtab161
⭐ Don’t forget to star the repo if you like it!