Skip to content

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: w vector of portfolio weights · Σ return covariance matrix · μ vector of expected returns · target_return required 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 on w before running it.

Efficient Frontier

return E[r] σ (risk) min variance portfolio tangency portfolio (max Sharpe) r_f CML single assets (dominated)
upper-left envelope = efficient frontier · tangency = max Sharpe portfolio · CML connects r₍f₎ to tangency: leveraging or de-levering this point dominates everything below

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 · P matrix mapping views to assets · Q vector 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.

d_ij = √(½ × (1 − ρ_ij))
clusters = hierarchical_cluster(d)
w = recursive_bisection(Σ, clusters)

where: d_ij correlation distance between assets i and j · ρ_ij Pearson correlation · clusters dendrogram 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

  1. Garbage In, Garbage Out — Expected returns are hard to estimate
  2. Use Shrinkage — Shrink covariance matrix estimates toward target
  3. Resample — Use Monte Carlo to account for estimation error
  4. Consider Transaction Costs — Rebalancing has costs
  5. Regular Rebalancing — Monthly or quarterly
  6. Risk Parity Over MV — More robust to estimation errors
  7. 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: w portfolio weights · μ expected returns · Σ covariance matrix · r_f risk-free rate · 1 vector of ones · RC_i risk contribution of asset i does: 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