Basic Prerequisites: 03 · Multivariable Calculus (gradients, Hessians, quadratic forms).
1. Intuition & Practical Objective
Unconstrained optimisation (“set the gradient to zero”) is almost never the problem a practitioner faces. Portfolios must be fully invested (), meet a return floor (), respect position caps, hit a target duration, match a benchmark beta. Every one of those is an equality or inequality constraint, and constraints change the first-order condition from "" to a bordered condition.
This page builds the machinery for optima under constraints:
- Lagrange multipliers for equality constraints - the geometric picture is “at the optimum the objective’s level set is tangent to the constraint surface,” so their gradients are parallel: .
- The multiplier is a shadow price - is the marginal improvement in the objective per unit of constraint relaxation. This is the single most useful output of a constrained optimisation after the answer itself.
- KKT conditions for inequality constraints - the generalisation that adds complementary slackness: a constraint either binds (and has a positive multiplier) or is slack (and has a zero multiplier), never both.
The canonical finance instance, used as the worked example below, is Markowitz mean–variance: minimise subject to and . Its KKT system is a linear system, which makes it the cleanest possible illustration of everything on this page.
2. Mathematical Ground Truth & Derivations
Equality-constrained optimisation (Lagrange). Consider subject to , . Form the Lagrangian
At a regular optimum (constraint gradients linearly independent - the constraint qualification) there exist multipliers such that
Geometrically: at the optimum lies in the span of the constraint gradients - the objective can improve no further while staying on the constraint surface.
KKT conditions (inequalities + equalities). For subject to and (Boyd eq. 5.49; Simon & Blume §18.6), form
At an optimum, with the constraint qualification holding, there are with the four KKT blocks:
Dropping the inequalities leaves the Lagrange conditions exactly. Under convexity of and affinity of (with Slater’s condition), KKT is necessary and sufficient: any point satisfying KKT is globally optimal with zero duality gap (Boyd §5.5.3).
The multiplier is a shadow price (envelope theorem). Replace by and let be the optimal value. Then at the optimum
Relaxing (or tightening) the constraint by one unit changes the objective by the multiplier. This is the envelope theorem (Simon & Blume §19.2), and it is why dual variables are read off a solver as “prices”: the portfolio’s return-constraint multiplier is the marginal cost in variance of demanding one more unit of expected return.
Complementary slackness as a decision rule. says: a constraint is either slack (then - it costs nothing to relax) or binding (then may be positive - it is doing work). With inequality caps on positions, this is precisely the statement “an asset is either at its cap () or interior ().”
Second-order conditions. Equality- and inequality-constrained problems need a bordered Hessian test (Simon & Blume §16.3, §19.3): for , the Hessian of the Lagrangian restricted to the constraint tangent space must be positive definite; the bordered Hessian
must have a specific alternating-sign pattern. The plain definiteness of is not the right test under constraints.
Worked example - the Markowitz KKT system. s.t. . The Lagrangian is , and KKT stationarity gives , which together with the two equality constraints is the linear system
This is Boyd’s Example 5.1 (equality-constrained convex QP) with the sign convention of the Lagrangian; it can be solved by Gaussian elimination from scratch.
3. Computational Implementation - Lagrange and the Markowitz KKT system
Stdlib only. Part (a) verifies the elementary Lagrange result s.t. ; part (b) assembles and solves the Markowitz KKT system with a hand-written Gaussian elimination, then verifies stationarity, the constraints, and the shadow price via the envelope theorem.
Read the output. The Lagrange result is exact and the brute-force check () confirms is the maximum. In (b): the weights sum to and deliver to ten decimals; the KKT stationarity residual is (machine zero), so holds exactly. The multiplier is the shadow price of the return constraint, and the envelope check confirms it: bumping upward raises at exactly rate per unit of return. That is the number a portfolio manager reads as “the marginal variance cost of demanding more return.”
4. Failure Modes & First-Principles Breakdowns
- The multiplier can fail to exist if the constraint qualification fails. If the active constraint gradients are linearly dependent at (Simon & Blume §19.5), the Lagrange/KKT system may have no solution even though an optimum exists. A common occurrence: two constraints that are “the same” (redundant caps), or a constraint with zero gradient at the point (an active bound of the form hit at a degenerate point).
- Sign conventions destroyed the shadow-price reading. Whether the Lagrangian is or flips the sign of . Get it wrong and the “shadow price” points the wrong way. (Here : the budget constraint’s multiplier is small and negative under this convention.)
- KKT is necessary only under convexity - otherwise it finds local optima. Add a cardinality cap or a non-convex cost and KKT still holds at a local optimum, but a different, better feasible point may exist elsewhere (page 06).
- Complementary slackness is easy to misread. A zero multiplier does not mean the constraint is irrelevant; it means it is slack at the optimum. Numerical solvers return tiny nonzero duals for active constraints with approximate tolerance - never threshold duals naively.
- The second-order condition is the bordered Hessian, not the Hessian. A point can satisfy KKT and have yet be a constrained maximum, or be a constrained minimum while is indefinite. Testing the wrong matrix gives the wrong answer (Simon & Blume §19.3).
- Ill-conditioned constraint systems amplify error. The KKT matrix in (b) is a saddle-point (indefinite) system - it is symmetric-indefinite, so a naive Cholesky fails and the multipliers can lose digits if the constraint rows are nearly collinear. The stationarity residual is the honest health check.
5. References
- Simon & Blume: Mathematics for Economists
- Boyd & Vandenberghe: Convex Optimization
- Nocedal, J. & Wright, S. J.: Numerical Optimization (2nd ed.)
- Bertsekas, Dimitri P.: Nonlinear Programming (3rd ed.)
6. Connected Graph Bridges
- Back: 03 · Multivariable Calculus · Index Hub
- Next: 05 · Gradient & Newton (solving the stationarity system iteratively) → 06 · Convexity & Applications
- Applied: Mean–Variance Optimization (the QP solved here) · Pricing Formulas (hedging as a constrained problem)
- Base: Linear Algebra & Matrices (linear systems, saddle-point structure)