σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
Optimization skill›Module 4 · Constraints and regularisation›Topic 4.1·~1 hrIntermediate

Constrained optimization and KKT

Skill positionModule 4 of 5 · Topic 1 of 4
4.1 Constrained optimization and KKT
—Lab score— / 100Total XP—Streak—

Optimising under rules

Real portfolios obey rules: the weights add up to one, no short sales, a cap on turnover. A constrained problem is min⁡f(w)\min f(\mathbf w)minf(w) subject to equalities h(w)=0h(\mathbf w)=0h(w)=0 and inequalities g(w)≤0g(\mathbf w)\le0g(w)≤0. With one equality, the best feasible point is where ∇f\nabla f∇f points straight through the constraint surface, because any sideways component could be used to improve fff without leaving the surface. That is the Lagrange condition ∇f+λ∇h=0\nabla f+\lambda\nabla h=0∇f+λ∇h=0, and the number λ\lambdaλ is the Lagrange multiplier. Collecting everything in the Lagrangian L=f+λh+μgL=f+\lambda h+\mu gL=f+λh+μg turns the constrained problem into the search for a stationary point of LLL.

∇f+λ∇h+μ∇g=0,h=0,g≤0,μ≥0,μ g=0\nabla f+\lambda\nabla h+\mu\nabla g=0,\qquad h=0,\quad g\le0,\qquad \mu\ge0,\qquad \mu\,g=0∇f+λ∇h+μ∇g=0,h=0,g≤0,μ≥0,μg=0(1)

For inequalities the full set of conditions, named after Karush, Kuhn and Tucker, has four parts: stationarity of the Lagrangian, primal feasibility (the constraints hold), dual feasibility (μ≥0\mu\ge0μ≥0) and complementary slackness (μg=0\mu g=0μg=0). Complementary slackness says each inequality is either inactive, with g<0g<0g<0 and μ=0\mu=0μ=0, so it does not matter, or active, with g=0g=0g=0 and μ>0\mu>0μ>0, so it acts like an equality. For a convex problem these conditions are necessary and sufficient for a global optimum. The multiplier is also a price: it is the rate at which the best value of fff improves when the constraint is relaxed by one unit.

Two small examplesMinimise x2+y2x^2+y^2x2+y2 subject to x+y=1x+y=1x+y=1. The Lagrange conditions 2x+λ=02x+\lambda=02x+λ=0 and 2y+λ=02y+\lambda=02y+λ=0 give x=y=−λ/2x=y=-\lambda/2x=y=−λ/2, and the constraint then gives λ=−1\lambda=-1λ=−1 and x=y=0.5x=y=0.5x=y=0.5, with value 0.50.50.5. If the constraint is relaxed to x+y=cx+y=cx+y=c, the best value becomes c2/2c^2/2c2/2, whose slope at c=1c=1c=1 is 1=−λ1=-\lambda1=−λ. Next, minimise (x−2)2(x-2)^2(x−2)2 subject to x≤1x\le1x≤1. The unconstrained minimum x=2x=2x=2 breaks the rule, so the constraint is active at x=1x=1x=1 and 2(x−2)+μ=02(x-2)+\mu=02(x−2)+μ=0 gives μ=2>0\mu=2>0μ=2>0. With the rule x≤3x\le3x≤3 instead, the unconstrained minimum is allowed and μ=0\mu=0μ=0.

The minimum-variance portfolio is the model case: minimise wTΣw\mathbf w^{T}\Sigma\mathbf wwTΣw subject to 1Tw=1\mathbf 1^{T}\mathbf w=11Tw=1. The Lagrange condition 2Σw+λ1=02\Sigma\mathbf w+\lambda\mathbf 1=02Σw+λ1=0 gives w∝Σ−11\mathbf w\propto\Sigma^{-1}\mathbf 1w∝Σ−11. For two uncorrelated assets with variances 0.040.040.04 and 0.090.090.09 the weights are proportional to 1/0.04=251/0.04=251/0.04=25 and 1/0.09=11.11/0.09=11.11/0.09=11.1, so w1=0.692w_1=0.692w1​=0.692, w2=0.308w_2=0.308w2​=0.308 and the portfolio variance is 1/(25+11.1)=0.02771/(25+11.1)=0.02771/(25+11.1)=0.0277. The multiplier equals −2-2−2 times that minimum variance. In a real portfolio a long-only rule or a turnover cap has its own multiplier, and a large μ\muμ tells you that rule is costing you a lot.

  • Equality constraint: ∇f+λ∇h=0\nabla f+\lambda\nabla h=0∇f+λ∇h=0 together with h=0h=0h=0.
  • Inequality: μ≥0\mu\ge0μ≥0 and μg=0\mu g=0μg=0; active means g=0g=0g=0, inactive means μ=0\mu=0μ=0.
  • Price: a multiplier is the sensitivity of the best value to a relaxation of its constraint.
Check feasibility and signsAfter solving, verify the answer against all four conditions. The most common slips are a multiplier with the wrong sign for an inequality (it must be μ≥0\mu\ge0μ≥0 when constraints are written g≤0g\le0g≤0) and an active constraint that was assumed inactive. Sign conventions differ between textbooks and libraries, so always read which form your solver expects.

Lab · what's graded

  • The multiplier10 pts
  • The optimal point10 pts
  • Relaxing the constraint10 pts
  • A two-asset minimum-variance weight15 pts
  • The minimum variance15 pts
  • The four KKT conditions15 pts
  • An active constraint10 pts
  • What a multiplier tells you15 pts
0/ 8 answered
Tasks
1Numeric answer10 ptsNot answered

Minimise x2+y2x^2+y^2x2+y2 subject to x+y=1x+y=1x+y=1 with the condition ∇f+λ∇h=0\nabla f+\lambda\nabla h=0∇f+λ∇h=0 for h=x+y−1h=x+y-1h=x+y−1. What is λ\lambdaλ?

lam=lam =lam=accepted: ± 0.01
2Numeric answer10 ptsNot answered

For the same problem, what is the optimal xxx?

x=x =x=accepted: ± 0.005
3Numeric answer10 ptsNot answered

The best value under x+y=cx+y=cx+y=c is c2/2c^2/2c2/2. What is the best value of x2+y2x^2+y^2x2+y2 when the constraint is x+y=3x+y=3x+y=3?

value=value =value=accepted: ± 0.01
4Numeric answer15 ptsNot answered

Two uncorrelated assets have variances 0.040.040.04 and 0.090.090.09. The minimum-variance weights are proportional to 1/σi21/\sigma_i^21/σi2​ and add up to one. What is the weight w1w_1w1​ of the first asset? Give it to three decimals.

w1=w1 =w1=accepted: ± 0.002
5Numeric answer15 ptsNot answered

What is the variance of that minimum-variance portfolio? It equals 1/∑i(1/σi2)1/\sum_i(1/\sigma_i^2)1/∑i​(1/σi2​). Give it to four decimals.

var=var =var=accepted: ± 0.0003
6Match15 ptsNot answered

Match each KKT condition with what it says.

Pick the partner of each item on the left.

Stationarity
Primal feasibility
Dual feasibility
Complementary slackness
7Choice10 ptsNot answered

Minimise (x−2)2(x-2)^2(x−2)2 subject to x≤1x\le1x≤1. What do the KKT conditions give?

8Explain in words15 ptsNot answered

In one or two sentences, say what a large multiplier on a turnover limit tells a portfolio manager.

Math modeKeyboard or LaTeX inputTask 1 of 8 · Ctrl ⏎ to check

Log in to run your code.

Every lecture is free to read. Create an account or log in to run code, run tests and submit this lab.

  • In-browser IDE with a bash terminal — nothing to install
  • Instant grading, XP and your place on the skill
Create an accountLog in
OR
Continue with GitHub