Quant Memo
Foundational

Lagrange Multipliers & KKT Conditions

The calculus of constrained optimization, Lagrange multipliers for equalities, the full Karush–Kuhn–Tucker conditions with complementary slackness for inequalities, and their application to the mean–variance efficient frontier.

Prerequisites: Convex Optimization

Almost every optimization a quant actually solves is constrained, weights sum to one, leverage is capped, positions are long-only, tracking error is bounded. Lagrange multipliers and their inequality-handling generalization, the Karush–Kuhn–Tucker (KKT) conditions, are the exact characterization of a constrained optimum: they tell you the equations the solution must satisfy and, as a bonus, the price of each constraint. This is the machinery that turns the Convex Optimization promise of "solvable" into an actual solution, and it is the derivation behind the entire mean–variance efficient frontier.

Equality constraints: the geometry of Lagrange

Consider minimizing f(x)f(x) subject to g(x)=0g(x) = 0. At an optimum xx^\star on the constraint surface, you cannot decrease ff by moving along the surface, so the descent direction f-\nabla f must have no component tangent to the surface, i.e. f\nabla f must be parallel to the constraint normal g\nabla g. That is the entire geometric content: f(x)=λg(x),\nabla f(x^\star) = \lambda\, \nabla g(x^\star), for some scalar λ\lambda, the Lagrange multiplier. Package this by forming the Lagrangian L(x,λ)=f(x)λg(x),\mathcal{L}(x, \lambda) = f(x) - \lambda\, g(x), and the stationarity conditions xL=0\nabla_x \mathcal{L} = 0 and L/λ=0\partial\mathcal{L}/\partial\lambda = 0 recover both the gradient-parallelism and the constraint g(x)=0g(x) = 0. With multiple equality constraints gi(x)=0g_i(x) = 0, the gradient of ff must lie in the span of the constraint gradients: f=iλigi\nabla f = \sum_i \lambda_i \nabla g_i. The multiplier is not just algebraic bookkeeping, λ=f/c\lambda^\star = \partial f^\star/\partial c is the sensitivity of the optimal value to relaxing the constraint level cc, its shadow price.

Inequality constraints: the KKT conditions

Real problems mix equalities with inequalities (hj(x)0h_j(x) \le 0: leverage caps, no-short constraints). The KKT conditions are the complete first-order characterization. For minxf(x)s.t.hj(x)0,  gi(x)=0,\min_x f(x)\quad\text{s.t.}\quad h_j(x)\le 0,\ \ g_i(x)=0, with Lagrangian L=f+jμjhj+iλigi\mathcal{L} = f + \sum_j \mu_j h_j + \sum_i \lambda_i g_i, a point xx^\star (with multipliers μ,λ\mu^\star, \lambda^\star) is optimal only if:

  1. Stationarity: f(x)+jμjhj(x)+iλigi(x)=0.\nabla f(x^\star) + \sum_j \mu_j^\star \nabla h_j(x^\star) + \sum_i \lambda_i^\star \nabla g_i(x^\star) = 0.
  2. Primal feasibility: hj(x)0, gi(x)=0.h_j(x^\star) \le 0,\ g_i(x^\star) = 0.
  3. Dual feasibility: μj0\mu_j^\star \ge 0 (inequality multipliers are non-negative, the constraint can only push back, not pull).
  4. Complementary slackness: μjhj(x)=0\mu_j^\star\, h_j(x^\star) = 0 for every jj.

Condition 4 is the conceptual heart. For each inequality constraint, either the multiplier is zero or the constraint is active (tight, hj=0h_j = 0): μj>0hj(x)=0\mu_j^\star > 0 \Rightarrow h_j(x^\star) = 0, and hj(x)<0μj=0h_j(x^\star) < 0 \Rightarrow \mu_j^\star = 0. In words, an inactive constraint has zero shadow price, and only binding constraints carry a price. A leverage cap you're not hitting doesn't affect your optimal portfolio; a cap you're pressed against has a positive multiplier equal to the marginal return you'd gain by loosening it. Complementary slackness is what lets you solve KKT systems by guessing the active set (which constraints bind), solving the resulting equality-constrained problem, and checking the sign conditions.

Sufficiency under convexity. For a general (non-convex) problem KKT is only necessary (and needs a constraint qualification like Slater's or LICQ). But for a convex problem, the KKT conditions are both necessary and sufficient: any point satisfying them is a global optimum. This is the precise sense in which convexity makes constrained problems solvable, you solve a system of equations and inequalities and you are done, with a global certificate. It is also exactly the strong-duality statement from Convex Optimization: the optimal KKT multipliers are the optimal dual variables.

Worked example, mean–variance with a return target

The efficient frontier is a KKT (here, pure-equality Lagrange) problem. Minimize variance subject to a target return and full investment: minw 12wΣws.t.μw=r,  1w=1.\min_w\ \tfrac12 w^\top\Sigma w \quad\text{s.t.}\quad \mu^\top w = r,\ \ \mathbf{1}^\top w = 1. Form L=12wΣwλ(μwr)γ(1w1)\mathcal{L} = \tfrac12 w^\top\Sigma w - \lambda(\mu^\top w - r) - \gamma(\mathbf{1}^\top w - 1). Stationarity in ww: wL=Σwλμγ1=0    w=Σ1(λμ+γ1).\nabla_w\mathcal{L} = \Sigma w - \lambda\mu - \gamma\mathbf{1} = 0 \;\Longrightarrow\; w^\star = \Sigma^{-1}(\lambda\mu + \gamma\mathbf{1}). The optimal portfolio is a linear combination of Σ1μ\Sigma^{-1}\mu (the The Kelly Criterion / tangency direction) and Σ11\Sigma^{-1}\mathbf{1} (the minimum-variance direction), the two-fund separation theorem falls straight out of the two multipliers. Substituting ww^\star back into the two constraints gives a 2×22\times2 linear system for λ\lambda and γ\gamma in terms of the scalars A=1Σ11A = \mathbf{1}^\top\Sigma^{-1}\mathbf{1}, B=1Σ1μB = \mathbf{1}^\top\Sigma^{-1}\mu, C=μΣ1μC = \mu^\top\Sigma^{-1}\mu, whose solution traces the entire frontier as rr varies. Because the problem is convex (Σ0\Sigma \succeq 0), this stationary point is the global minimum, the multipliers are the answer, not a candidate. See MPT (Harry Markowitz) for the frontier this generates. Adding a long-only constraint w0w \ge 0 turns it into a genuine inequality-KKT problem where complementary slackness decides which names sit at the zero boundary.

Failure modes and subtleties

  • KKT is only necessary without convexity. For non-convex ff, a KKT point can be a local min, a saddle, or a max; you must check second-order conditions or global structure. Convexity is what promotes KKT to sufficient.
  • Constraint qualifications matter. KKT presumes the constraint gradients are well-behaved at xx^\star (LICQ, or Slater's for convex problems). At degenerate points (redundant or tangentially-meeting constraints) multipliers can fail to exist or be non-unique, and naive solvers stall.
  • Sign conventions bite. Inequality multipliers must be 0\ge 0 with the constraints written as hj0h_j \le 0; flipping a constraint's sign flips the required multiplier sign. A multiplier coming out negative usually means you mislabeled an active constraint or the "constraint" isn't actually binding.
  • Guessing the active set can be combinatorial. With many inequalities, the number of possible active sets is exponential; this is why real solvers use interior-point or active-set algorithms rather than brute-forcing complementary slackness. KKT tells you what to verify, not how to search efficiently.
  • Shadow prices assume smoothness and local validity. λ=f/c\lambda^\star = \partial f^\star/\partial c is a marginal, valid for small perturbations; large constraint changes can shift the active set and invalidate the linear sensitivity.

In interviews

The mean–variance derivation is the canonical test: set up the Lagrangian, take the gradient, and produce w=Σ1(λμ+γ1)w^\star = \Sigma^{-1}(\lambda\mu + \gamma\mathbf{1}), ideally naming two-fund separation. Be able to give the geometric intuition for Lagrange multipliers, gradients parallel at the optimum, not just the mechanics. For inequality problems, state all four KKT conditions and explain complementary slackness in plain terms (inactive constraints have zero price), since that is the piece candidates most often miss. Know that KKT is necessary-and-sufficient only under convexity, tying back to Convex Optimization. A strong close is interpreting the multiplier as a shadow price, the marginal value of a risk budget or leverage limit, which shows you understand constrained optimization as economics, not just calculus.

Related concepts

Practice in interviews

Further reading

  • Boyd & Vandenberghe, Convex Optimization (Ch. 5)
  • Nocedal & Wright, Numerical Optimization (Ch. 12)
  • Bertsekas, Nonlinear Programming
ShareTwitterLinkedIn