Skip to content

This notebook explores the optimization of a portfolio's Sharpe ratio using the Markowitz efficient frontier approach. By sweeping over a range of target returns and solving a series of minimum-variance problems, the optimal risk-adjusted portfolio (maximum Sharpe ratio) is identified.

Notifications You must be signed in to change notification settings

mirkovicdev/Sharpe-ratio-optimization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ˆ Sharpe Ratio Optimizer via Markowitz Sweep

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.


๐Ÿง  What It Does

Given:

  • A covariance matrix of asset returns $\Sigma$
  • A vector of expected returns $\mu$
  • A specified risk-free rate $R_f$

The optimizer solves:

$$ \max_w \quad \frac{\mu^T w - R_f}{\sqrt{w^T \Sigma w}} \quad \text{subject to} \quad \sum w_i = 1, \quad w_i \geq 0 $$

Rather than solving this non-convex problem directly, it:

  1. Sweeps through a range of target returns
  2. Solves a minimum-variance problem for each
  3. Computes Sharpe ratios
  4. Selects the portfolio with the highest Sharpe ratio

๐Ÿ” Features

  • โœ… 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

๐Ÿ“Š Visualization

  • Efficient frontier: risk vs expected return
  • Max Sharpe point: highlighted
  • Capital Market Line: from risk-free rate tangent to the frontier

๐Ÿ“ฆ Requirements

  • Python 3.x
  • NumPy
  • CVXPY
  • Matplotlib

Install dependencies:

pip install numpy cvxpy matplotlib

About

This notebook explores the optimization of a portfolio's Sharpe ratio using the Markowitz efficient frontier approach. By sweeping over a range of target returns and solving a series of minimum-variance problems, the optimal risk-adjusted portfolio (maximum Sharpe ratio) is identified.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published