Know these first
- M-A02: Rearranging equations
By the end you will be able to
- 1Find a minimum or maximum of a function of one variable with f′ = 0, and tell which it is from f″.
- 2Find the stationary point of a function of two variables by setting both partial derivatives to zero.
- 3Solve a problem with one equality constraint using a Lagrange multiplier, and read the multiplier as a shadow price.
- 4Set up and solve a problem with two equality constraints, one multiplier each.
Why you need it
The smallest risk for a given return. The largest return for a given risk. Optimisation finds the best choice, and Lagrange multipliers find it when the choice has to obey rules, such as weights that add up to 100%.
These Core Path lessons use it:
L3.1.04: The minimum-variance portfolio
The minimum-variance portfolio minimises a variance subject to one constraint: the weights add up to 1.
L3.1.07: Mean-variance optimisation
Mean-variance optimisation adds a second constraint, a target return; its multiplier prices that target.
You need derivatives from M-B01: Derivatives and the second derivative from M-B03: Taylor expansion. The two-variable case uses partial derivatives, introduced here in one step.
The idea
The lowest point on a fence
Picture a bowl-shaped valley, drawn as contour lines, and a straight fence across it. You may only stand on the fence. Where is the lowest point you can reach? Walk along it and watch the height.
Walk along the fence
f = x² + 2y², fence x + y = 3Ellipses: contours of f (the highlighted one is f = 6). Purple line: the fence. Arrows: ∇f (blue) and ∇g (purple).
∇f and ∇g point different ways, so walking along the fence still changes f. Find where they line up.
At the lowest point on the fence, the fence just touches one contour without crossing it. There, the direction of steepest climb, the gradient ∇f, is at right angles to the fence, just like the fence's own gradient ∇g. So ∇f is a multiple of ∇g. That multiple is the Lagrange multiplier.
The rules
One variable. The first-order condition finds the flat spots; the second-order condition sorts them.
Two variables, no constraint. One partial derivative per variable, all set to zero.
One constraint. The tangency in the picture, turned into equations with a Lagrange multiplier.
What λ means. The multiplier is not just a helper: it is a shadow price.
Two constraints. One multiplier per constraint, and the same steps.
The rules, for reference
Try it
Minimise a x² + b y² on the fence x + y = c. Change the shape of the bowl and move the fence. Watch where the best point lands, and check that λ predicts how much the best value rises when the fence moves out by 0.1.
Try itMinimum on a fence
Calculus calculator →Minimise 1x² + 2y² subject to x + y = 3
Shadow price check: raise c by 0.1
Worked examples
1. Stationary points of a cubic
Step 1 of 4- 1
The set-up
2. One constraint, and its shadow price
Step 1 of 5- 1
The set-up
3. Two constraints: three funds
Step 1 of 5- 1
The set-up
Three illustrative funds with volatilities 20%, 10%, 15% and expected returns 8%, 3%, 6%. To keep the algebra short, take them as uncorrelated, so by M-C11: Combining random variables the variance of a mix is a sum of squares. Find the weights with the smallest variance that add up to 1 and give an expected return of 6%:
Returns in %, so the variance is in %².
Common mistakes
Each line below is a tempting slip. Spot what is wrong, then check.
Reaction
Check what stuck
Question 1 · objective 1
f(x) = x² − 6x + 2. At what x is f′(x) = 0?
Question 2 · objective 1
At x*, f′(x*) = 0 and f″(x*) = −4. What is x*?
Question 3 · objective 2
Minimise x² + y² subject to x + y = 4, with 𝓛 = x² + y² − λ(x + y − 4). What is λ*?
Question 4 · objective 3
A minimum has multiplier λ* = 2.5. Roughly how much does the best value change if the constraint's c rises by 0.2?
Question 5 · objective 4
You minimise a function of three unknowns subject to two equality constraints. How many equations do you solve?
Glossary
- Stationary point
- A point where the derivative (or every partial derivative) is zero: a flat spot that may be a minimum, a maximum or neither.
- First-order condition
- The condition that the first derivative is zero at the best point: f′(x*) = 0, or ∇f = 0 in several variables.
- Second-order condition
- The check on the second derivative that tells a minimum (f″ > 0) from a maximum (f″ < 0).
- Partial derivative
- The derivative of a function of several variables with respect to one of them, holding the others fixed: ∂f/∂x.
- Gradient (∇f)
- The vector of all partial derivatives, ∇f. It points in the direction in which f rises fastest.
- Constraint
- A condition the answer must satisfy, such as x + y = 3, written g(x, y) = c.
- Lagrangian (𝓛)
- 𝓛 = f − λ(g − c): the function whose partial derivatives, set to zero, give the constrained optimum.
- Lagrange multiplier (λ)
- The extra unknown λ in the Lagrangian, one per constraint. At the optimum, ∇f = λ∇g.
- Shadow price
- The rate at which the best value changes as a constraint is loosened: df*/dc = λ.