Portfolio Optimization¶
Difficulty advanced
Overview¶
Portfolio optimization finds the asset allocation that maximizes return for a given level of risk, or minimizes risk for a given level of return.
Modern Portfolio Theory (Markowitz)¶
Efficient Frontier¶
For a given set of assets, find weights that:
Minimize: w'Σw (portfolio variance)
Subject to: w'μ = target_return, Σw_i = 1
where:
wvector of portfolio weights ·Σreturn covariance matrix ·μvector of expected returns ·target_returnrequired portfolio return does: the mean-variance optimization problem — used to trace the efficient frontier and select the tangency (max Sharpe) portfolio; in practice highly sensitive to inputs, so apply shrinkage toΣand constraints onwbefore running it.
Efficient Frontier¶
Black-Litterman Model¶
Incorporates investor views with market equilibrium:
E[R] = [(τΣ)⁻¹ + P'Ω⁻¹P]⁻¹ × [(τΣ)⁻¹Π + P'Ω⁻¹Q]
where:
Π = Market equilibrium returns
P = Pick matrix (which assets the views apply to)
Q = View returns
Ω = Uncertainty in views
τ = Scaling factor
where:
Πreverse-optimized market-implied returns ·Σreturn covariance matrix ·Pmatrix mapping views to assets ·Qvector of view returns ·Ωconfidence (covariance) of the views ·τscalar reflecting confidence in the prior does: the Black-Litterman posterior — blends market-implied equilibrium returns with explicit investor views weighted by stated confidence; used for institutional allocation decisions when raw mean-variance generates extreme weights and analysts want to anchor on market consensus while expressing tilts.
Hierarchical Risk Parity (HRP)¶
Uses hierarchical clustering on the correlation matrix to allocate without ever inverting the covariance matrix. The three-step pipeline: (1) cluster assets by correlation distance, (2) quasi-diagonalize the covariance matrix to put similar assets next to each other, (3) recursively split risk budget between clusters using inverse-variance weights.
where:
d_ijcorrelation distance between assetsiandj·ρ_ijPearson correlation ·clustersdendrogram from single/Ward linkage ·Σcovariance matrix used only on diagonal blocks does: allocates capital by recursively splitting risk between correlation clusters — used for large universes (hundreds of assets) where mean-variance breaks down from near-singular covariance; produces more stable out-of-sample weights than Markowitz in De Prado's tests.
Constraints¶
| Constraint Type | Example | Implementation |
|---|---|---|
| Long only | w_i ≥ 0 | bounds = (0, 1) |
| Max weight | w_i ≤ 0.25 | bounds = (0, 0.25) |
| Sector limit | Σ sector weights ≤ 0.3 | Linear constraint |
| Turnover | w_new - w_old | |
| Cardinality | At most 10 positions | Integer constraint |
Practical Guidelines¶
- Garbage In, Garbage Out — Expected returns are hard to estimate
- Use Shrinkage — Shrink covariance matrix estimates toward target
- Resample — Use Monte Carlo to account for estimation error
- Consider Transaction Costs — Rebalancing has costs
- Regular Rebalancing — Monthly or quarterly
- Risk Parity Over MV — More robust to estimation errors
- Don't Over-Optimize — Simple 1/N often beats complex optimization
Key Formulas Reference¶
Portfolio Return: R_p = w'μ
Portfolio Variance: σ²_p = w'Σw
Sharpe Ratio: (w'μ - r_f) / √(w'Σw)
Min Variance: w = Σ⁻¹1 / (1'Σ⁻¹1)
Max Sharpe: w = Σ⁻¹(μ - r_f) / sum
Risk Parity: RC_i = RC_j for all i,j
where:
wportfolio weights ·μexpected returns ·Σcovariance matrix ·r_frisk-free rate ·1vector of ones ·RC_irisk contribution of assetidoes: the canonical closed-form solutions for the most common portfolio constructions — used as a quick-reference for code implementation; min-variance for low-vol mandates, max-Sharpe for unconstrained alpha, risk parity for robustness when expected returns are unreliable.
Next Steps¶
- Position Sizing — Individual position sizing
- Correlation Analysis — Understanding correlations
- Kelly Criterion — Optimal growth theory