EconStatsCraft › Portfolio optimization

Portfolio optimization

Takes the sample means and covariance of several return series and finds the minimum-variance and maximum-Sharpe portfolios, traces the efficient frontier, and shows how far inside it every single asset sits.

What it needs

Frequently asked questions

What is portfolio optimization?

Portfolio optimization chooses the weights of assets to get the highest expected return for a given level of risk, or the lowest risk for a given return. In Markowitz mean-variance optimization, risk is the portfolio variance, which depends on every pair of assets' covariance, not just their individual volatilities.

What is the efficient frontier?

The efficient frontier is the curve of portfolios that offer the best possible expected return at each level of volatility. Any portfolio below it is inefficient: another mix of the same assets gives more return for the same risk.

What is the maximum Sharpe ratio portfolio?

It is the portfolio on the efficient frontier with the highest excess return per unit of volatility. With a risk-free asset, every investor should hold this one risky portfolio and adjust risk by mixing it with cash or borrowing, which traces out the capital market line.

What is the minimum variance portfolio?

The minimum variance portfolio is the leftmost point of the efficient frontier: the lowest-volatility mix of the assets, chosen without using expected returns at all. Because expected returns are the hardest input to estimate, it is often more stable out of sample than the maximum-Sharpe portfolio.

Why do optimized portfolio weights look extreme?

Mean-variance optimization treats estimated returns as exact, so it piles into assets whose returns happen to be overestimated. Constraining weights (no short selling, position limits), using longer data or shrinking the inputs gives more sensible weights.

The intuition

Given several assets, some combinations are simply better than others: same expected return for less risk. Plot every possible mix and the good ones trace out a curve, the efficient frontier. The mathematics is a constrained optimisation, but the economics is one idea - correlations below one mean a mix is less risky than its parts, and that free reduction in risk is the only free lunch in finance.

When to use it

Asset allocation, constructing a benchmark-agnostic portfolio, teaching diversification, or showing why holding many imperfectly-correlated assets beats holding the best one.

Where the estimator comes from

Minimise portfolio variance w'\Sigma w subject to w'\mu=\mu_p and w'\mathbf{1}=1. The Lagrangian gives a closed form: with A=\mathbf{1}'\Sigma^{-1}\mathbf{1}, B=\mathbf{1}'\Sigma^{-1}\mu and C=\mu'\Sigma^{-1}\mu, the minimum-variance frontier is the parabola \sigma_p^2=(A\mu_p^2-2B\mu_p+C)/(AC-B^2). The global minimum-variance portfolio is w=\Sigma^{-1}\mathbf{1}/A and needs no expected returns at all, which is why it is far more stable in practice. Adding a risk-free asset gives the tangency portfolio w\propto\Sigma^{-1}(\mu-R_f\mathbf{1}), the mix with the highest Sharpe ratio.

The model

\min_{w}\; w^{\top}\Sigma\,w \quad\text{s.t.}\quad w^{\top}\mathbf{1}=1,\; w^{\top}\mu = \bar{r};\qquad w_{\text{tan}} \propto \Sigma^{-1}(\mu - r_f\mathbf{1})

What it assumes

Statistical properties

How to read the output

A worked reading

Five funds, and the global minimum-variance portfolio puts 100% of the money into one of them - the defensive fund, which happens to have the lowest volatility of the five (3.1691 against 5.17 to 6.47). That is the honest face of an unconstrained optimiser: nothing in the objective rewards diversification for its own sake, so if one asset dominates the covariance structure the solution is a corner. The resulting portfolio has an expected return of 0.5529 per period (6.635% annualised) at a volatility of 3.1691 (10.978% annualised). Notice what that means for the tangency portfolio further down, which adds expected RETURNS to the problem: minimum-variance uses only the covariance matrix, which is estimated reasonably well from 180 observations, while tangency also needs the means, which are not - the standard error on a mean return is roughly the volatility over the square root of the sample, and over any realistic sample that is large relative to the differences between assets. It is why minimum-variance weights are usually the ones worth taking to a client and tangency weights usually are not.

Symptom → diagnosis → what to do

If you see thisIt meansDo this
Weights of +300% and -200%Unconstrained optimiser on noisy meansImpose no-short, or use the minimum-variance portfolio
Weights change completely with one more month of dataEstimation error dominatingShrink the covariance matrix; do not trust the point solution
One asset takes almost everythingIts sample mean is the highest, probably by luckCheck what happens with equal weights
Frontier is nearly a straight lineAssets are highly correlatedThere is little diversification to be had here
Covariance matrix will not invertMore assets than periodsShrinkage, or fewer assets
Tangency portfolio has a Sharpe ratio above 2In-sample overfittingThis will not survive out of sample

Common mistakes

Where to read this properly

See also

Ridge / Lasso / Elastic Net, which is the same estimation-error problem in a regression - shrinking noisy estimates towards something stabler is exactly what a minimum-variance constraint does to weights. Value at Risk, for the tail rather than the variance.

Related Finance & risk

Black–Scholes option pricing · Bond price, duration & convexity · Merton distance to default · EMI / home loan planner · CAPM / beta estimation · Multi-factor model · Value at Risk & Expected Shortfall · Performance & drawdown · Time value of money & NPV/IRR · Equity valuation (DDM, FCF, residual income) · Cost of capital (WACC) · Binomial option pricing · Option strategies (payoff & profit) · Forwards, futures & swaps · Credit risk & Basel capital · Extreme value theory (tail risk)

All analyses

Charts

Line chart · Area chart · Bar chart · Stacked bar · Scatter plot · Bubble chart · Histogram · Box plot · Pie chart · Heat map · Rebased to 100 · Lorenz curve and Gini

Maps

World map · Bivariate map · Flow map · India - state map · India - district map

Explore

Descriptive statistics · Summary by group · Two-way table · Classical statistical tests

Regression

Multiple regression (OLS) · Logit / Probit · Tobit (censored) · Truncated regression · Multinomial logit · Ordered logit / probit · Quantile regression · Poisson / Negative binomial

Time series - one series

Time-varying coefficients (Kalman) · Unit root tests · Correlogram (ACF / PACF) · ARIMA / SARIMA · Rolling-origin cross-validation · Theta method · Unobserved components · STL forecasting · Forecast combination · Markov regime switching · Change frequency (resample) · ARCH / GARCH volatility · Decompose & filter · Spectral analysis · Exponential smoothing · Forecast accuracy

Time series - several series

Yield curve (Nelson–Siegel / Svensson) · Dynamic factor model · Dynamic regression (ARIMAX) · Structural VAR · VAR · Granger causality · Cointegration · VECM · ARDL & bounds test

Panel data

Panel regression · Panel cointegration tests · Heterogeneous panel: Mean Group & PMG · Gravity model of trade · Dynamic panel GMM · Panel diagnostics · Panel unit-root tests

Multivariate statistics

Principal components (PCA) · Factor analysis · Cluster analysis

Marketing research

Conjoint analysis · MaxDiff (best–worst scaling) · TURF - reach of a product line · Price sensitivity (Van Westendorp) · Market basket analysis · Perceptual map · Scale reliability (Cronbach’s alpha) · Key driver analysis

Causal

Spatial autocorrelation · Spatial regression · Heckman selection · Instrumental variables (2SLS) · Difference-in-differences · Staggered difference-in-differences · Regression discontinuity · Matching & weighting · Oaxaca–Blinder decomposition

Finance & risk

Black–Scholes option pricing · Bond price, duration & convexity · Merton distance to default · EMI / home loan planner · CAPM / beta estimation · Multi-factor model · Portfolio optimization · Value at Risk & Expected Shortfall · Performance & drawdown · Time value of money & NPV/IRR · Equity valuation (DDM, FCF, residual income) · Cost of capital (WACC) · Binomial option pricing · Option strategies (payoff & profit) · Forwards, futures & swaps · Credit risk & Basel capital · Extreme value theory (tail risk)

Actuarial

Life table · Life annuity · Life insurance pricing · Chain ladder reserving · Buhlmann credibility · Survival analysis · Mortality graduation · Aggregate loss model · Ruin probability · Multi-state Markov model · Loss severity fitting

Tests & breaks

Monte Carlo experiment · F-test, Wald & Chow · Structural breaks & stability

Machine learning

Regression vs machine learning · Ridge / Lasso / Elastic Net · Random forest · Gradient boosting

Open the workspace →

Starting engine…

EconStatsCraft rigorous, plain-spoken econometrics

Econometrics that explains itself.

Regression, panel data, time series and the whole battery of tests. Every result is followed by a verdict you can defend.

Load a dataset to see it here.