This project implements a classical Markowitz mean–variance portfolio optimization in Python.
It constructs the efficient frontier, identifies the minimum-variance and maximum-Sharpe (tangency) portfolios, and visualizes allocations and trade-offs.
portfolio-optimization/ ├─ main.ipynb # Jupyter notebook with full workflow ├─ requirements.txt # Dependencies ├─ README.md # Project overview ├─ LICENSE # MIT License ├─ .gitignore # Ignore build/checkpoint files └─ plots/ # Figures saved automatically
-
Data collection
- Downloaded adjusted close prices from Yahoo Finance via
yfinance.
- Downloaded adjusted close prices from Yahoo Finance via
-
Returns & covariance
- Daily log returns → annualized expected returns (μ) and covariance matrix (Σ).
-
Optimization
- Minimum-variance portfolio (lowest volatility).
- Maximum-Sharpe portfolio (tangency portfolio, relative to risk-free rate).
- Efficient frontier constructed by sweeping target returns.
-
Visualization
- Efficient frontier with Capital Market Line.
- Portfolio weights bar charts.
Data & setup
- Tickers: AAPL, MSFT, GOOGL, AMZN, META, JPM, XOM, SPY
- Sample: 2020-01-01 to 2025
- Risk-free rate: 3% annualized
Optimal portfolios
-
Minimum-Variance Portfolio
- Expected return: 14.02%
- Volatility: 20.85 %
- Weights: see plots/weights_minvar.png
-
Max-Sharpe Portfolio
- Expected return: 20.63 %
- Volatility: 25.70 %
- Sharpe ratio: 0.686
- Weights: see plots/weights_maxsharpe.png
Figures
Interpretation
- The efficient frontier illustrates the classic trade-off between expected return and risk (σ).
- The minimum-variance portfolio concentrates on stable, low-volatility assets.
- The tangency portfolio maximizes the Sharpe ratio, balancing risk and return.
- Under no-short constraints, allocations are bounded between 0–1, producing a conservative frontier compared to unconstrained optimization.
- Use covariance shrinkage estimators (e.g., Ledoit–Wolf).
- Run rolling-window analysis for time-varying portfolios.
- Add sector/weight caps or transaction cost modeling.
- Compare with alternative risk measures (CVaR, MAD).
- 2025-10-08: Initial project setup, data pipeline, returns/covariance.
- 2025-10-09: Implemented optimization (min-var, max-Sharpe) and efficient frontier.
- 2025-10-10: Added visualizations, results interpretation, and README polish.
This project is licensed under the MIT License.


