Skip to content
LeetQuant
F6 Linear Algebra and Optimisation

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)f(x) subject to g(x)=cg(x) = c. Walk along the constraint surface. If ∇f\nabla f had any component along the surface, you could move that way and lower ff. So at a constrained optimum, ∇f\nabla f is perpendicular to the surface, i.e. parallel to ∇g\nabla g:

∇f(x∗)=λ ∇g(x∗).\nabla f(x^*) = \lambda\,\nabla g(x^*) .

Package this as the Lagrangian L(x,λ)=f(x)−λ(g(x)−c)\mathcal L(x, \lambda) = f(x) - \lambda\big(g(x) - c\big) and set all its partial derivatives to zero: ∇xL=0\nabla_x\mathcal L = 0 is the alignment condition, ∂L/∂λ=0\partial\mathcal L/\partial\lambda = 0 gives back the constraint. With mm constraints, ∇f=∑jλj∇gj\nabla f = \sum_j \lambda_j\nabla g_j: the gradient lies in the span of the constraint gradients. (This needs the constraint gradients to be linearly independent at x∗x^*, which holds for linear constraints that are not redundant.)

These are necessary conditions. To know you have a minimum, use convexity (convex ff 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)f^*(c) be the optimal value as a function of the constraint level. Then

df∗dc=λ.\frac{df^*}{dc} = \lambda .

(Sketch: f∗(c)=L(x∗(c),λ∗(c);c)f^*(c) = \mathcal L(x^*(c), \lambda^*(c); c), and by the envelope theorem only the explicit dependence on cc survives, which is +λ+\lambda.) So λ\lambda 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+2y2x^2 + 2y^2 subject to x+y=3x + y = 3. Then estimate the new minimum if the constraint becomes x+y=3.1x + y = 3.1.

Show solution

L=x2+2y2−λ(x+y−3)\mathcal L = x^2 + 2y^2 - \lambda(x + y - 3).

∂L∂x=2x−λ=0,∂L∂y=4y−λ=0,x+y=3.\frac{\partial\mathcal L}{\partial x} = 2x - \lambda = 0, \qquad \frac{\partial\mathcal L}{\partial y} = 4y - \lambda = 0, \qquad x + y = 3 .

So x=λ/2x = \lambda/2 and y=λ/4y = \lambda/4, giving 3λ/4=33\lambda/4 = 3: λ=4\lambda = 4, x=2x = 2, y=1y = 1, minimum 4+2=64 + 2 = 6. The objective is convex and the constraint linear, so this is the global minimum.

Shadow price: raising cc by 0.10.1 changes the minimum by about λ×0.1=0.4\lambda \times 0.1 = 0.4, to about 6.46.4. Exactly: the solution scales with cc as x=2c/3x = 2c/3, y=c/3y = c/3, so f∗(c)=2c2/3f^*(c) = 2c^2/3, f∗(3.1)=6.4067f^*(3.1) = 6.4067, and df∗/dc=4c/3=4df^*/dc = 4c/3 = 4 at c=3c = 3.

Deriving the minimum-variance portfolio

Minimise w⊤Σww^\top\Sigma w subject to 1⊤w=1\mathbf 1^\top w = 1, with Σ\Sigma PD.

L=w⊤Σw−λ(1⊤w−1),∇wL=2Σw−λ1=0 ⟹ w=λ2Σ−11.\mathcal L = w^\top\Sigma w - \lambda(\mathbf 1^\top w - 1), \qquad \nabla_w\mathcal L = 2\Sigma w - \lambda\mathbf 1 = 0 \ \Longrightarrow\ w = \tfrac{\lambda}{2}\Sigma^{-1}\mathbf 1 .

The budget fixes λ\lambda: λ2 1⊤Σ−11=1\tfrac\lambda2\,\mathbf 1^\top\Sigma^{-1}\mathbf 1 = 1. Writing A=1⊤Σ−11A = \mathbf 1^\top\Sigma^{-1}\mathbf 1,

w∗=Σ−11A,σmin⁡2=w∗⊤Σw∗=1A,λ=2A=2σmin⁡2.w^* = \frac{\Sigma^{-1}\mathbf 1}{A}, \qquad \sigma^2_{\min} = w^{*\top}\Sigma w^* = \frac{1}{A}, \qquad \lambda = \frac{2}{A} = 2\sigma^2_{\min} .

Read the first-order condition: 2Σw∗=λ12\Sigma w^* = \lambda\mathbf 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 cc, weights and variance scale as cc and c2c^2, so σmin⁡2(c)=c2/A\sigma^2_{\min}(c) = c^2/A and its derivative at c=1c = 1 is 2/A=λ2/A = \lambda.

Adding a return target μ⊤w=m\mu^\top w = m gives a second multiplier and w=Σ−1(a1+bμ)w = \Sigma^{-1}(a\mathbf 1 + b\mu), a mix of two fixed portfolios. With B=1⊤Σ−1μB = \mathbf 1^\top\Sigma^{-1}\mu, C=μ⊤Σ−1μC = \mu^\top\Sigma^{-1}\mu and D=AC−B2D = AC - B^2, the frontier is the parabola

σ2(m)=Am2−2Bm+CD,\sigma^2(m) = \frac{Am^2 - 2Bm + C}{D},

minimised at m=B/Am = 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 solution

Σ=(0.040.0200.020.040000.01)\Sigma = \begin{pmatrix} 0.04 & 0.02 & 0 \\ 0.02 & 0.04 & 0 \\ 0 & 0 & 0.01 \end{pmatrix}. It is block diagonal, so invert the blocks: (0.040.020.020.04)−1=10.0012(0.04−0.02−0.020.04)\begin{pmatrix} 0.04 & 0.02 \\ 0.02 & 0.04 \end{pmatrix}^{-1} = \dfrac{1}{0.0012}\begin{pmatrix} 0.04 & -0.02 \\ -0.02 & 0.04 \end{pmatrix}.

Σ−11=(0.020.0012, 0.020.0012, 100)=(1623, 1623, 100),A=13313.\Sigma^{-1}\mathbf 1 = \Big(\tfrac{0.02}{0.0012},\ \tfrac{0.02}{0.0012},\ 100\Big) = \big(16\tfrac23,\ 16\tfrac23,\ 100\big), \qquad A = 133\tfrac13 .

So w∗=(1/8, 1/8, 3/4)w^* = (1/8,\ 1/8,\ 3/4), σmin⁡2=1/A=0.0075\sigma^2_{\min} = 1/A = 0.0075, σmin⁡≈8.66%\sigma_{\min} \approx 8.66\%, and λ=2/A=0.015\lambda = 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)=λ12\Sigma w^* = 2(0.0075,\ 0.0075,\ 0.0075) = (0.015,\ 0.015,\ 0.015) = \lambda\mathbf 1.

Intuition check: an equal mix of assets 1 and 2 has variance 14(0.04+0.04+2×0.02)=0.03\tfrac14(0.04 + 0.04 + 2 \times 0.02) = 0.03. Inverse-variance weighting between that mix (0.03) and asset 3 (0.01) gives weights 14\tfrac14 and 34\tfrac34, matching the answer.

Inequality constraints: KKT

Minimise f(x)f(x) subject to hi(x)≤0h_i(x) \le 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=0h_i = 0, so it behaves like an equality, but it can only push in one direction). The Karush–Kuhn–Tucker conditions encode this:

  1. Stationarity: ∇f(x∗)+∑iμi∇hi(x∗)=0\nabla f(x^*) + \sum_i \mu_i\nabla h_i(x^*) = 0 (plus λj\lambda_j terms for equalities).
  2. Primal feasibility: hi(x∗)≤0h_i(x^*) \le 0.
  3. Dual feasibility: μi≥0\mu_i \ge 0. The constraint can only push you back inside the feasible region, never pull you out.
  4. Complementary slackness: μihi(x∗)=0\mu_i h_i(x^*) = 0. Either the constraint binds or its price is zero.

For a convex ff with convex hih_i 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\mu_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.

Show solution

Unconstrained. σ12=0.8×0.1×0.2=0.016\sigma_{12} = 0.8 \times 0.1 \times 0.2 = 0.016.

w1=σ22−σ12σ12+σ22−2σ12=0.04−0.0160.01+0.04−0.032=0.0240.018=43,w2=−13.w_1 = \frac{\sigma_2^2 - \sigma_{12}}{\sigma_1^2 + \sigma_2^2 - 2\sigma_{12}} = \frac{0.04 - 0.016}{0.01 + 0.04 - 0.032} = \frac{0.024}{0.018} = \tfrac43, \qquad w_2 = -\tfrac13 .

Shorting asset 2 pays because it is highly correlated with asset 1 but riskier: ρ=0.8>σ1/σ2=0.5\rho = 0.8 > \sigma_1/\sigma_2 = 0.5.

Long-only. Add −w2≤0-w_2 \le 0 (and −w1≤0-w_1 \le 0). The unconstrained answer violates w2≥0w_2 \ge 0, so guess that constraint binds: w=(1,0)w = (1, 0). Check KKT with L=w⊤Σw−λ(w1+w2−1)−μ1w1−μ2w2\mathcal L = w^\top\Sigma w - \lambda(w_1 + w_2 - 1) - \mu_1 w_1 - \mu_2 w_2:

2Σw=(2×0.01, 2×0.016)=(0.020, 0.032).2\Sigma w = (2 \times 0.01,\ 2 \times 0.016) = (0.020,\ 0.032) .

w1>0w_1 > 0, so μ1=0\mu_1 = 0 by complementary slackness, and the first row gives λ=0.020\lambda = 0.020. The second row gives μ2=0.032−0.020=0.012≥0\mu_2 = 0.032 - 0.020 = 0.012 \ge 0. Every condition holds and the problem is convex, so w=(1,0)w = (1, 0) is optimal, with volatility 10%.

Interpretation: μ2=0.012\mu_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)(1 - t, t) changes the variance at rate ddtσ2=−0.020+0.032=0.012\tfrac{d}{dt}\sigma^2 = -0.020 + 0.032 = 0.012 at t=0t = 0.

Knowledge check

What is the maximum of x+yx + y subject to x2+y2=2x^2 + y^2 = 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\nabla f = \sum_j\lambda_j\nabla g_j. Solve ∇L=0\nabla\mathcal L = 0, then confirm optimality by convexity or by comparison.
  • λ=df∗/dc\lambda = df^*/dc: the shadow price of the constraint.
  • Minimum variance: w∗=Σ−11/(1⊤Σ−11)w^* = \Sigma^{-1}\mathbf 1/(\mathbf 1^\top\Sigma^{-1}\mathbf 1), variance 1/(1⊤Σ−11)1/(\mathbf 1^\top\Sigma^{-1}\mathbf 1), and every held asset has equal marginal variance at the optimum.
  • KKT for inequalities: stationarity, feasibility, μi≥0\mu_i \ge 0, and μihi=0\mu_i h_i = 0. A constraint either binds with a non-negative price or is slack with price zero. For convex problems these conditions are sufficient.

Practice problems

Finished reading?

Answer the 4 knowledge checks to complete this lesson (0 done).