Quadratic Programming
Minimum-variance portfolio construction is a quadratic program: minimise a bowl-shaped risk function subject to straight-line constraints — a problem structured enough to be solved fast, reliably, and exactly.
Prerequisites: Convex Sets and Convex Functions, Lagrange Multipliers & KKT Conditions, Cholesky Decomposition
Every portfolio optimiser you've ever heard of — mean-variance, minimum-variance, risk parity's convex cousins — is solving the same shape of problem underneath: minimise a quadratic risk expression subject to a handful of straight-line rules like "weights sum to one" and "no short positions." That shape has a name, quadratic programming, and the reason it deserves its own name rather than being lumped in with general optimisation is that this particular shape is special enough to be solved exactly, fast, and reliably — no trial and error required.
The analogy: finding the lowest point on a tilted, fenced bowl
Picture a bowl-shaped valley (portfolio variance, genuinely bowl-shaped because variance is a convex quadratic function of weights) sitting inside a fenced field with straight fences (the constraints: weights between 0 and 1, weights summing to 1). If the bowl's lowest point happens to fall inside the fence, that's your answer — done. If the unconstrained lowest point falls outside the fence, the true answer must sit against one of the straight fences, at the point closest to the bowl's true bottom. Because both the bowl (quadratic) and the fences (straight lines) are simple, predictable shapes, there's no need to search randomly for this point — you can reason directly about which fence, if any, the answer leans against, and solve for the exact spot. That reasoning, formalised, is quadratic programming.
Writing it down
A quadratic program has the general form: minimise
In words: is the vector of decision variables (portfolio weights). is a matrix (the covariance matrix, in a risk-minimisation problem) that shapes the bowl — it must be positive semidefinite for the problem to be convex, i.e. genuinely bowl-shaped rather than saddle-shaped. is a linear term (can tilt the bowl, e.g. penalising expected-return shortfall). collects every inequality constraint (position limits, no-short rules) and collects every equality constraint (fully invested, dollar-neutral).
The solution is characterised by the Karush-Kuhn-Tucker (KKT) conditions, the natural extension of "set the derivative to zero" to a constrained problem:
In words: at the optimum, the bowl's gradient is exactly balanced by a weighted combination of the constraint directions it's pressed against — and are the Lagrange multipliers (shadow prices, from duality) on the inequality and equality constraints. The last condition, called complementary slackness, says a constraint's multiplier can only be nonzero if that constraint is exactly binding — pressed right up against the fence, with zero slack. If a constraint isn't binding, its multiplier is zero and it plays no role at the optimum, exactly matching the intuition that a fence you're not touching shouldn't affect where you stand.
Because is positive semidefinite (a convex bowl) and the constraints are linear (straight fences), the KKT conditions are not just necessary but sufficient — solve them and you have provably found the global optimum, with no risk of a better answer hiding elsewhere. That certainty is exactly what convexity buys.
Picture the ellipse this explorer draws as a slice through the quadratic bowl at a fixed height — a level set of . The shape of that ellipse is governed entirely by : round means all directions are equally risky, elongated means one combination of assets is far riskier than another, and a straight fence (a constraint) cutting across it is exactly where the optimum gets pinned if the unconstrained minimum falls outside.
Worked example 1: unconstrained minimum-variance weight, by hand
Two assets, variances , , correlation (uncorrelated, for clean arithmetic), weight in asset 1 and in asset 2. Variance is . Setting : , so .
Check: this is the standard inverse-variance weighting result, — matches exactly. Minimum variance: , or volatility.
Worked example 2: adding a binding constraint, by hand
Now impose a maximum position limit: . Since the unconstrained optimum violates it, the constraint is binding — the true optimum sits exactly at the fence, , by the same "closest point on a convex bowl outside a convex fence is on the fence" logic. Variance at : , or volatility — worse than the unconstrained , as it must be, since a binding constraint can only hurt or leave unchanged the objective.
Verify via KKT: the multiplier on the constraint should satisfy (one-dimensional version of the stationarity condition). , so — a positive multiplier, consistent with a genuinely binding constraint (a negative multiplier here would signal the KKT point was actually a maximum pressed against the wrong side of the fence, a standard sign-check quants run to sanity-test a solver's output).
What this means in practice
- It's the exact machinery behind minimum-variance and mean-variance optimisers. Any solver labelled "QP solver" in a portfolio construction pipeline — quadprog, OSQP, CVXOPT — is solving precisely this KKT system, usually via an interior-point or active-set method rather than by hand.
- Position limits and turnover constraints slot in as extra linear rows. Because the QP framework only needs , , , to be linear, adding realistic trading constraints (no more than 5% turnover, sector-neutral, leverage capped) doesn't change the solution method at all — just the size of the constraint matrices.
- A non-positive-semidefinite breaks everything. An estimated covariance matrix that fails to be positive semidefinite (common with more assets than data points) turns the "bowl" into a saddle, and the QP solver either fails or returns a nonsensical answer — see Cholesky as the standard diagnostic.
A quadratic program minimises a convex quadratic objective () subject to linear constraints — exactly the shape of minimum-variance and mean-variance portfolio problems. Because both the bowl and the fences are simple, the KKT conditions are not just necessary but sufficient for a global optimum, which is why QP solvers are trusted to return the exact answer rather than an approximate one.
The classic confusion is assuming any optimisation problem "with an in it somewhere" counts as a quadratic program that inherits these guarantees. It does not — the objective must be convex quadratic (positive semidefinite ) and every constraint must be genuinely linear. Swap in a non-convex risk measure (like a cardinality constraint capping the number of positions, or a non-convex downside-risk objective) and the clean KKT-implies-global-optimum guarantee disappears entirely, even though the problem might still superficially "look quadratic." Practitioners sometimes hand a genuinely non-convex portfolio problem to a QP solver expecting the same reliability as mean-variance, and get a locally-optimal but not globally-optimal answer with no warning that anything went wrong.
Related concepts
Practice in interviews
Further reading
- Nocedal & Wright, Numerical Optimization (ch. 16)
- Boyd & Vandenberghe, Convex Optimization (ch. 4)