An investor has a sum of money to divide between a number of risky assets — shares, bonds, funds. Each asset has an uncertain return. Putting everything into the asset with the highest expected return is rarely wise, because that asset is usually also the most volatile; spreading the money reduces risk, but by how much, and at what cost in expected return?
Portfolio optimization makes this trade-off precise. Markowitz (1952) proposed measuring risk by the variance of the portfolio return, which turns portfolio selection into a quadratic program. The resulting picture — the efficient frontier — is still the starting point of quantitative asset management. This lecture develops the mean–variance model, works it out in closed form, and then looks at a tail-risk alternative, CVaR, which leads to a linear program.
The decision
There are assets indexed by . Over the investment period, asset has a random return (for example means the asset gains 8%). We summarize the joint distribution of returns by two quantities:
- the expected returns , collected in a vector ;
- the covariance matrix , with entries . Its diagonal holds the variances , and where is the correlation.
The decision is the vector of portfolio weights , where is the fraction of wealth placed in asset . The weights sum to one. A negative weight is a short position: the investor borrows the asset, sells it, and must buy it back later.
The portfolio return is , so
The expected return is linear in ; the variance is a quadratic form. Because is a covariance matrix it is positive semidefinite, so the variance is a convex function of the weights.
Formulation
The mean–variance model asks for the least risky portfolio that achieves a required expected return :
The objective is the portfolio variance. The first constraint fixes the expected return at the target (writing it as an inequality gives the same answer whenever is above the return of the minimum-variance portfolio). The second says all wealth is invested; is the vector of ones. There is no sign constraint on , so short selling is allowed for now.
This is a convex quadratic program: a convex quadratic objective with linear constraints. Two equivalent variants are common: maximize subject to a variance cap , or maximize for a risk-aversion parameter . Varying , or traces out the same set of optimal portfolios.
A portfolio is efficient if no other portfolio has a higher expected return with the same or lower variance, or a lower variance with the same or higher expected return. Plotting standard deviation against expected return, the efficient portfolios form a curve called the efficient frontier. The portfolio with the smallest variance of all is the global minimum-variance portfolio; the efficient frontier is the part of the minimum-variance curve lying above it.
Solution methods
Closed form via the KKT conditions
Assume is positive definite (no asset is a riskless combination of the others) and is not a multiple of . Since the problem is convex with only equality constraints, the Karush–Kuhn–Tucker conditions are necessary and sufficient. With multipliers for the return constraint and for the budget, stationarity of the Lagrangian reads
Every optimal portfolio is therefore a combination of just two vectors, and . Substituting into the two constraints and writing
gives two linear equations for and , and hence the frontier.
The minimum variance attainable at expected return is
a parabola in and a hyperbola in . It is smallest at , which is the expected return of the global minimum-variance portfolio , whose variance is . Moreover the multiplier satisfies : it is the marginal variance cost of demanding one more unit of expected return.
The last statement is the familiar shadow-price reading of a Lagrange multiplier, here in a nonlinear setting.
The two-asset case
With two assets and , the budget and return constraints leave no freedom at all: each target return pins down a single portfolio, and the frontier is simply the curve traced out as varies. The variance is
Setting the derivative to zero gives the minimum-variance weight and variance
Whenever is less than (taking asset 1 as the less volatile), is strictly less than one and the mixture is less risky than either asset alone. This is diversification, and the lower the correlation the stronger the effect: with the risk can be eliminated entirely.
Asset 1 has , ; asset 2 has , ; the correlation is , so . Then
The minimum-variance mix holds about 71% in asset 1 and 29% in asset 2. Its standard deviation is about — lower than the of the safer asset on its own — and its expected return is about , higher than asset 1's. Moving from "all in asset 1" to this mix improves both risk and return, so holding asset 1 alone is inefficient.
General solvers
With constraints beyond the two equalities — no short selling, sector limits, turnover caps — there is no closed form, but the problem remains a convex QP. Interior-point and active-set QP solvers handle thousands of assets routinely. The covariance matrix is often supplied in factor form (a few risk factors plus diagonal idiosyncratic risk), which solvers exploit to avoid forming a dense matrix.
Worked example
Expected returns and covariance matrix are
that is, volatilities of 20%, 30% and 40%, with correlations , , .
Solving the KKT system — three stationarity equations plus the two constraints, five linear equations in — for gives, exactly,
The portfolio variance is , a standard deviation of about . Asset 2 alone also has an expected return of 10%, but with a standard deviation of 30%: diversification removes over a third of the risk at no cost in expected return.
For the frontier formula, , , and . Plugging in reproduces , and the derivative matches . The global minimum-variance portfolio is with expected return and standard deviation .
A few points on the frontier (all computed numerically and checked against the formula):
| Target | Std. dev. | |||
|---|---|---|---|---|
| 8.03% (GMV) | 0.633 | 0.226 | 0.141 | 16.33% |
| 10% | 0.336 | 0.328 | 0.336 | 19.38% |
| 12% | 0.034 | 0.431 | 0.534 | 26.64% |
| 13% | −0.116 | 0.483 | 0.634 | 31.00% |
At a target of 13% the optimal portfolio shorts asset 1: it borrows the low-return asset to buy more of the high-return ones. That is the cue for the next section.
No short selling
Many investors — pension funds, most retail accounts — may not hold negative positions. Adding gives
This is still a convex QP, but the closed form is lost: the KKT conditions now include complementary slackness, only if the stationarity equation for asset holds with equality. In effect the solver must discover which assets to hold. The target can now be met only if .
With and , the optimizer drops asset 1 entirely. With only assets 2 and 3 left, the target pins the portfolio down: and give , with variance and standard deviation , against when shorting is allowed. At the 10% target the constraint is inactive — the unconstrained optimum already has all weights positive — so nothing changes there. At the only feasible portfolio is all in asset 3.
The constrained frontier lies on or to the right of the unconstrained one and coincides with it wherever the unconstrained weights happen to be non-negative.
CVaR minimization as a linear program
Variance penalizes gains and losses symmetrically, and it says little about the tail — the bad outcomes regulators and risk managers care about most. A tail-focused alternative is the conditional value-at-risk.
Let be the portfolio loss (the negative of the return) and a confidence level such as . The value-at-risk is the -quantile of : losses exceed it with probability at most . The conditional value-at-risk is, roughly, the expected loss given that the loss is in the worst tail. With finitely many equally likely scenarios and times the number of scenarios a whole number , it is exactly the average of the largest losses.
VaR is not convex in the weights and is awkward to optimize. CVaR is convex, and Rockafellar and Uryasev (2000) showed it can be written as a minimization over an auxiliary variable :
where , and the minimizing is a VaR.
Now approximate the return distribution by scenarios: scenario has probability and return vector , for example from historical data or simulation. The loss in scenario is . Introducing to stand for gives the linear program
Here is the scenario mean return. At the optimum each equals the amount by which the scenario loss exceeds the threshold , or zero, so the objective is exactly the CVaR of the portfolio. The model has variables and roughly constraints, so it scales to tens of thousands of scenarios with an ordinary LP solver.
Ten equally likely scenarios give the following returns, in percent:
| Scenario | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Mean |
|---|---|---|---|---|---|---|---|---|---|---|---|
| Asset 1 | 4 | 7 | 9 | 7 | −1 | 8 | 1 | 7 | 1 | 4 | 4.7 |
| Asset 2 | 1 | 4 | 20 | 12 | 4 | 1 | 4 | 5 | 1 | 1 | 5.3 |
| Asset 3 | 5 | 12 | 3 | 23 | 6 | 21 | 18 | 2 | −3 | 10 | 9.7 |
Take , so the tail is the worst scenarios, and require a mean return of at least 7% with no short selling. The LP optimum (solved with HiGHS) is
The mean return constraint is binding at exactly 7%. The worst scenario is scenario 9, a loss of about ; next come scenarios 1 and 5, tied at a loss of (a gain of 3.5%), which is the VaR. The CVaR is the average of the two worst losses, : even in the worst fifth of outcomes the portfolio gains about 1.4% on average. For comparison, asset 3 alone — the only single asset meeting the 7% target — has a CVaR of , an average loss of 0.5% in its two worst scenarios.
The dual value of the return constraint is about : raising the target by one percentage point increases the optimal CVaR by about . Dropping the return target altogether, the minimum-CVaR portfolio is , with CVaR but a mean return of only .
Scenario-based CVaR solutions can be sensitive to the particular scenarios drawn, and with few scenarios the optimum is often not unique. In practice one uses many scenarios and checks stability by re-solving on resampled data.
Practical issues
The textbook model is elegant but fragile. Real portfolio construction adds several layers.
- Estimation error. and are estimated from data, and the optimizer treats the estimates as truth. It overweights assets whose expected returns happen to be overestimated — "error maximization". Expected returns are especially hard to estimate. Common remedies are shrinkage estimators for , factor models, blending with an equilibrium prior (the Black–Litterman approach), weight bounds, and robust optimization, which minimizes risk against the worst in an uncertainty set.
- Transaction costs and turnover. Moving from current holdings to costs money. Proportional costs can be linearized by splitting each trade into a purchase and a sale with ; the model remains a QP. Fixed costs per trade need binary variables.
- Cardinality and minimum-holding constraints. Managers often want at most assets, and any asset held to be held in at least a minimum size . With binary indicating whether asset is held,
where is an upper bound on the weight. The model becomes a mixed-integer quadratic program (or a MIP, with a CVaR or other linear risk measure). These are much harder; branch and bound with good bounds handles hundreds of assets, and heuristics are used beyond that.
- Multi-period and liabilities. Pension funds and insurers must match future liabilities. This leads to multi-stage stochastic programs and asset–liability management models.
Further reading: Cornuéjols, Peña and Tütüncü, Optimization Methods in Finance, covers mean–variance, CVaR and the integer extensions; Luenberger, Investment Science, gives the financial background.