Basic Prerequisites: 04 · Constrained Optimization (KKT, multipliers) and 05 · Gradient & Newton (iterative solvers).


1. Intuition & Practical Objective

This page collects the three ideas that turn the calculus of the previous pages into a toolbox a practitioner can trust, and shows each one doing finance work:

  1. Convexity is the property that makes the difference between “the solver found an answer” and “the solver found the answer.” Convex objective and convex feasible set every stationary point is a global optimum, and KKT is sufficient. It is also a fragility: the moment you add a cardinality cap or a non-convex cost, the guarantee evaporates.
  2. Duality turns a constrained problem into an unconstrained one and, in the convex case, gives a certificate of optimality (zero duality gap). Its by-product - the dual variables - are the shadow prices of page 04, recovered here as the slope of the value function (the envelope theorem) and as the engine of the efficient frontier.
  3. Regularisation (ridge, lasso) is constrained optimisation in disguise: the Lagrangian of “minimise the loss subject to a budget on the coefficients” is “minimise loss penalty,” and the lasso’s solution - soft-thresholding - is read off the KKT conditions rather than computed.

The three examples below are deliberately the ones a quant meets in week one: a convex QP (portfolio), a duality/envelope check, and a lasso fit by coordinate descent.


2. Mathematical Ground Truth & Derivations

Convex sets and functions. A set is convex if for all . A function is convex if its domain is convex and

For functions on a convex domain there is a computable test: convex for all . A convex optimisation problem is s.t. ( convex), ( affine). The two facts that make convex problems tractable:

  • Every local minimum is global. (If is locally optimal and is feasible with , convexity along the segment contradicts local optimality.)
  • KKT is sufficient (and, with Slater’s condition, necessary): any KKT point is globally optimal with zero duality gap (Boyd §5.5.3).

Strong convexity (, Boyd eq. 9.7) additionally makes the minimiser unique and gives the linear rate of page 05.

Lagrangian duality. For s.t. , the Lagrangian is with , and the dual function is . The dual problem is . Two facts:

  • Weak duality always: for every feasible dual - the dual gives a lower bound on the primal optimum, i.e. a certificate.
  • Strong duality for convex problems (Slater): - the bound is tight and the dual optimum can be found instead of the primal.

The envelope theorem / shadow prices. Differentiating where is the constraint level: (Simon & Blume §19.2). In the Markowitz problem, differentiating along the efficient frontier: the derivative of the frontier is the dual variable of the return constraint. The frontier is convex (concave in return–variance space), and its slope is the price of risk implied by the constraints.

Regularisation as constrained optimisation. Elastic-net / lasso (ESL §3.4):

For an orthonormal design () the solution is the soft-threshold operator, and it is read directly off the KKT conditions:

because the first-order condition has the subdifferential for and at . Ridge is the analogue: (ESL eq. 3.44), the shrinkage factor on the SVD direction (eq. 3.47) - a smooth, differentiable, convex problem, the clean case; the lasso is convex but non-smooth, which is exactly why its solution is sparse (it can sit exactly at ).

Where convexity is lost. Cardinality (“at most names”), fixed transaction costs, non-convex risk measures, and integer constraints all destroy convexity. The KKT conditions still hold at any local optimum, but a global certificate is gone.


3. Computational Implementation - convex vs non-convex, duality, and the lasso KKT

Stdlib only. (A) gradient descent from several starts on a convex and a non-convex objective, showing global uniqueness versus basin-dependence; (B) a duality/envelope check; (C) soft-thresholding solving the lasso KKT and coordinate descent recovering it.

Read the output. (A) The convex objective converges to the same point from every start - global uniqueness in action. The non-convex has two basins: starts at and land at , starts at and land at . Same code, same objective, different answers depending on the start - the failure mode convexity is there to prevent. (B) The best dual value equals the primal optimum to six decimals (gap ), so strong duality holds; and the envelope theorem’s is exactly the numeric . (C) The soft-threshold estimate has a KKT residual of exactly zero - it is the optimum, read off the first-order condition - and coordinate descent reproduces it. Here both , so both coefficients are merely shrunk ( and ); had a fallen below , soft-thresholding would have set that coefficient to exactly zero. That sparsity is a consequence of the non-smooth penalty (the KKT condition has a whole interval of subgradients at ), not of any explicit selection rule.


4. Failure Modes & First-Principles Breakdowns

  1. Convexity is a guarantee you can lose in one constraint. Experiment (A) is the whole point: “at most names,” fixed costs, or a non-convex risk measure make the objective multi-basin, and every gradient method becomes start-dependent. Report the basin, not just the answer.
  2. Weak duality is not strong duality. For a non-convex problem the dual only gives a lower bound; the gap can be strictly positive, so a dual solution is not a primal optimum. Always confirm convexity (or Slater) before treating the dual as the answer.
  3. KKT at a local optimum is not a global certificate. KKT holds at every local min of a smooth problem. It is the convexity that upgrades it to a global statement - the conditions alone do not.
  4. Shadow prices change sign and meaning with the constraint’s direction. A "" floor and a "" cap on the same quantity have opposite-signed multipliers; and a multiplier of zero means slack, not irrelevant. Misreading a dual from a solver is a classic and expensive bug.
  5. regularisation is non-smooth. The gradient does not exist at ; plain gradient descent cannot handle it (use subgradient, proximal/soft-threshold, or coordinate descent). Conversely the ridge problem is smooth and convex - the reason it has a closed form and lasso does not.
  6. Elastic-net/penalty scale is a data-unit decision. penalises raw coefficients; if the predictors are not standardised, the effective penalty differs per feature and the “sparsity” is an artefact of units, not of signal (ESL §3.4). Standardise first.
  7. Convex problems can still be numerically hard. Convexity says the optimum exists and is reachable; it says nothing about the conditioning. An ill-conditioned convex QP is still slow and unstable (page 05, failure mode 2).

5. References

  • Boyd & Vandenberghe: Convex Optimization
  • Simon & Blume: Mathematics for Economists
  • Hastie, Tibshirani & Friedman: The Elements of Statistical Learning (2nd ed.)
  • Rockafellar, R. T.: Convex Analysis (1970)
  • Bertsekas, Dimitri P.: Nonlinear Programming (3rd ed.)

6. Connected Graph Bridges