This project implements a Sharpe ratio-maximizing portfolio optimizer using the Markowitz efficient frontier method in Python with NumPy and CVXPY.
It visualizes the tangency portfolio where the Capital Market Line (CML) is tangent to the efficient frontierโhighlighting the optimal risk-return tradeoff.
Given:
- A covariance matrix of asset returns
$\Sigma$ - A vector of expected returns
$\mu$ - A specified risk-free rate
$R_f$
The optimizer solves:
Rather than solving this non-convex problem directly, it:
- Sweeps through a range of target returns
- Solves a minimum-variance problem for each
- Computes Sharpe ratios
- Selects the portfolio with the highest Sharpe ratio
- โ Finds the maximum Sharpe ratio portfolio using convex optimization
- โ Visualizes the efficient frontier and Capital Market Line (CML)
- โ Supports long-only portfolios (no short-selling)
- โ Handles arbitrary asset count
- โ Extensible to unconstrained or cardinality-constrained models
- โ Cleanly structured with theory-explaining comments and plots
- Efficient frontier: risk vs expected return
- Max Sharpe point: highlighted
- Capital Market Line: from risk-free rate tangent to the frontier
- Python 3.x
- NumPy
- CVXPY
- Matplotlib
Install dependencies:
pip install numpy cvxpy matplotlib