Portfolio Optimization
Portfolio optimization allocates capital across assets to maximize return for a given risk level. Markowitz mean-variance optimization is the canonical framework.
Key Points
- Mean-variance optimization trades expected return against variance.
- The efficient frontier is the set of optimal portfolios.
- Constraints (no short selling, sector limits) lead to quadratic programming.
Formulas
Mean-variance objective
$$\min_w \frac{1}{2} w^\top \Sigma w - \lambda w^\top \mu$$
Budget constraint
$$\sum_i w_i = 1$$
Sharpe ratio
$$\frac{\mathbb{E}[R_p] - R_f}{\sigma_p}$$
Code Example
import numpy as np
from scipy.optimize import minimize
mu = np.array([0.08, 0.12, 0.10])
Sigma = np.array([[0.04, 0.02, 0.01],
[0.02, 0.09, 0.03],
[0.01, 0.03, 0.05]])
def objective(w):
return 0.5 * w @ Sigma @ w - 0.5 * mu @ w
res = minimize(objective, [0.33, 0.33, 0.34],
constraints={'type': 'eq', 'fun': lambda w: np.sum(w) - 1})
print(res.x)