F6 · Linear Algebra and Optimisation · Lesson 5 of 5
Lagrange Multipliers and Constrained Optimisation
Equality constraints with Lagrange multipliers, multipliers as shadow prices, a full minimum-variance derivation, and KKT conditions for inequality constraints such as no shorting.
20 min
The geometry: gradients line up
Minimise f(x) subject to g(x)=c. Walk along the constraint surface. If ∇f had any component along the surface, you could move that way and lower f. So at a constrained optimum, ∇f is perpendicular to the surface, i.e. parallel to ∇g:
∇f(x∗)=λ∇g(x∗).
Package this as the LagrangianL(x,λ)=f(x)−λ(g(x)−c) and set all its partial derivatives to zero: ∇xL=0 is the alignment condition, ∂L/∂λ=0 gives back the constraint. With m constraints, ∇f=∑jλj∇gj: the gradient lies in the span of the constraint gradients. (This needs the constraint gradients to be linearly independent at x∗, which holds for linear constraints that are not redundant.)
These are necessary conditions. To know you have a minimum, use convexity (convex f with linear constraints means any solution of the conditions is a global minimum) or compare the candidate points directly.
Objective: set up and solve Lagrangian problems quickly, interpret the multiplier, derive the minimum-variance portfolio in matrix form, and handle inequality constraints with KKT.
The multiplier is a price
Let f∗(c) be the optimal value as a function of the constraint level. Then
dcdf∗=λ.
(Sketch: f∗(c)=L(x∗(c),λ∗(c);c), and by the envelope theorem only the explicit dependence on c survives, which is +λ.) So λ is the shadow price of the constraint: how much the objective would improve or worsen per unit of relaxation. In economics it is the marginal utility of income; in a risk budget it is the marginal variance of the budget; in a margin-constrained strategy it is what one more dollar of capacity is worth. A multiplier of zero says the constraint is not costing you anything.
Worked example
a two-variable problem and its shadow price
Minimise x2+2y2 subject to x+y=3. Then estimate the new minimum if the constraint becomes x+y=3.1.
Show solutionHide solution
L=x2+2y2−λ(x+y−3).
∂x∂L=2x−λ=0,∂y∂L=4y−λ=0,x+y=3.
So x=λ/2 and y=λ/4, giving 3λ/4=3: λ=4, x=2, y=1, minimum 4+2=6. The objective is convex and the constraint linear, so this is the global minimum.
Shadow price: raising c by 0.1 changes the minimum by about λ×0.1=0.4, to about 6.4. Exactly: the solution scales with c as x=2c/3, y=c/3, so f∗(c)=2c2/3, f∗(3.1)=6.4067, and df∗/dc=4c/3=4 at c=3.
Deriving the minimum-variance portfolio
Minimise w⊤Σw subject to 1⊤w=1, with Σ PD.
L=w⊤Σw−λ(1⊤w−1),∇wL=2Σw−λ1=0⟹w=2λΣ−11.
The budget fixes λ: 2λ1⊤Σ−11=1. Writing A=1⊤Σ−11,
w∗=AΣ−11,σmin2=w∗⊤Σw∗=A1,λ=A2=2σmin2.
Read the first-order condition: 2Σw∗=λ1 says every asset has the same marginal variance at the optimum. If one asset had a lower marginal variance, shifting a little weight into it would reduce risk. The multiplier checks out as a shadow price: with budget c, weights and variance scale as c and c2, so σmin2(c)=c2/A and its derivative at c=1 is 2/A=λ.
Adding a return target μ⊤w=m gives a second multiplier and w=Σ−1(a1+bμ), a mix of two fixed portfolios. With B=1⊤Σ−1μ, C=μ⊤Σ−1μ and D=AC−B2, the frontier is the parabola
σ2(m)=DAm2−2Bm+C,
minimised at m=B/A, the return of the minimum-variance portfolio.
Worked example
three assets
Assets 1 and 2 each have 20% volatility and correlation 0.5; asset 3 has 10% volatility and is uncorrelated with both. Find the minimum-variance portfolio, its volatility, and the multiplier.
Show solutionHide solution
Σ=0.040.0200.020.040000.01. It is block diagonal, so invert the blocks: (0.040.020.020.04)−1=0.00121(0.04−0.02−0.020.04).
So w∗=(1/8,1/8,3/4), σmin2=1/A=0.0075, σmin≈8.66%, and λ=2/A=0.015.
Check the equal-marginal-variance condition: 2Σw∗=2(0.0075,0.0075,0.0075)=(0.015,0.015,0.015)=λ1.
Intuition check: an equal mix of assets 1 and 2 has variance 41(0.04+0.04+2×0.02)=0.03. Inverse-variance weighting between that mix (0.03) and asset 3 (0.01) gives weights 41 and 43, matching the answer.
Inequality constraints: KKT
Minimise f(x) subject to hi(x)≤0 (and any equality constraints, handled as before). An inequality constraint is either slack at the optimum (it does not bind, so it behaves as if absent) or active (hi=0, so it behaves like an equality, but it can only push in one direction). The Karush–Kuhn–Tucker conditions encode this:
Stationarity:∇f(x∗)+∑iμi∇hi(x∗)=0 (plus λj terms for equalities).
Primal feasibility:hi(x∗)≤0.
Dual feasibility:μi≥0. The constraint can only push you back inside the feasible region, never pull you out.
Complementary slackness:μihi(x∗)=0. Either the constraint binds or its price is zero.
For a convex f with convex hi and linear equalities (plus a strictly feasible point, Slater's condition), the KKT conditions are necessary and sufficient. That covers long-only, position-limit and leverage-limited portfolio problems.
In practice: guess which constraints bind, solve the resulting equality problem, then check signs. A negative μi means that constraint wants to be released; a violated slack constraint means it should have been active. Quadratic-programming solvers automate this active-set search.
Worked example
no-shorting with KKT
Asset 1 has 10% volatility, asset 2 has 20%, correlation 0.8. Find the minimum-variance portfolio with and without a no-shorting constraint, and the multiplier on that constraint.
Shorting asset 2 pays because it is highly correlated with asset 1 but riskier: ρ=0.8>σ1/σ2=0.5.
Long-only. Add −w2≤0 (and −w1≤0). The unconstrained answer violates w2≥0, so guess that constraint binds: w=(1,0). Check KKT with L=w⊤Σw−λ(w1+w2−1)−μ1w1−μ2w2:
2Σw=(2×0.01,2×0.016)=(0.020,0.032).
w1>0, so μ1=0 by complementary slackness, and the first row gives λ=0.020. The second row gives μ2=0.032−0.020=0.012≥0. Every condition holds and the problem is convex, so w=(1,0) is optimal, with volatility 10%.
Interpretation: μ2=0.012 is the rate at which variance would rise if you were forced to hold asset 2. Directly, moving to (1−t,t) changes the variance at rate dtdσ2=−0.020+0.032=0.012 at t=0.
Knowledge check
What is the maximum of x+y subject to x2+y2=2?
Knowledge check
In a cost-minimisation problem with the constraint 'output = 100', the optimal multiplier is 3. Approximately how does the minimum cost change if required output rises to 102?
Knowledge check
In a long-only minimum-variance problem, an asset ends up with weight 0.3. What is the KKT multiplier on its constraint w ≥ 0?
Knowledge check
Three uncorrelated assets have volatilities 20%, 20% and 10%. What is the volatility of the fully invested minimum-variance portfolio?
Key takeaways
At an equality-constrained optimum, ∇f=∑jλj∇gj. Solve ∇L=0, then confirm optimality by convexity or by comparison.
λ=df∗/dc: the shadow price of the constraint.
Minimum variance: w∗=Σ−11/(1⊤Σ−11), variance 1/(1⊤Σ−11), and every held asset has equal marginal variance at the optimum.
KKT for inequalities: stationarity, feasibility, μi≥0, and μihi=0. A constraint either binds with a non-negative price or is slack with price zero. For convex problems these conditions are sufficient.