Why convexity is the dividing line
The earlier lesson on gradients and Hessians showed the headline fact: for a convex function every local minimum is global and a zero gradient certifies optimality. This lesson is about using that fact in practice. In optimisation the useful split is not linear versus nonlinear but convex versus nonconvex: convex problems with thousands of variables solve reliably in milliseconds with a certificate of optimality, while nonconvex ones (even a quadratic with a cardinality constraint) are NP-hard in general.
So the practical skill is recognition: given a portfolio or estimation problem, can you show it is convex by composing known pieces, and if it is not, can you reformulate it so that it is?
Objective: build convex functions and sets from a small set of rules, use strong convexity and smoothness to predict convergence and certify accuracy, and convert standard quant problems (tracking error, CVaR, maximum Sharpe, risk parity) into convex form.
Convex sets
A set is convex if it contains the segment between any two of its points: and imply .
| Convex | Why |
|---|---|
| Hyperplane , half-space | linear |
| Polyhedron | intersection of half-spaces |
| Norm ball | triangle inequality |
| Ellipsoid , | a norm ball in disguise |
| PSD cone | |
| Sublevel set of a convex | from the definition of convex |
Intersections of convex sets are convex, which is why stacking linear constraints, norm bounds and risk limits keeps a problem convex. The long-only, fully invested set is the simplex; adding sector caps, a leverage bound or a risk limit keeps it convex.
The constraints that break convexity are the ones a portfolio manager asks for most often:
- Cardinality, "at most 20 names": the set of vectors with at most nonzeros is a union of subspaces. The midpoint of and has two nonzeros.
- Minimum position size, " or ": a gap in the middle.
- A risk target as an equality, : the surface of an ellipsoid. The midpoint of and is . Replace it by (usually binding anyway if you maximise return).
- A lower bound on a convex function, : a superlevel set of a convex function is generally not convex.
These are handled by mixed-integer solvers, heuristics (solve the convex relaxation, then round and re-solve), or by moving them into the objective.
Convex functions and the rules that preserve them
Recall the definition and its smooth equivalents: ; equivalently ; equivalently everywhere. Checking a Hessian is often painful. Instead, build from atoms with rules that preserve convexity:
- Non-negative weighted sums: with .
- Affine pre-composition: is convex if is. So , and are convex.
- Pointwise maximum or supremum: , or over any index set. A worst case over scenarios of a convex loss is convex.
- Composition: is convex if is convex and non-decreasing and is convex (so and are convex). With convex non-increasing, must be concave.
- Partial minimisation: if is jointly convex in , then is convex in .
Atoms: affine functions, with , any norm, , , , , , and for .
Two quant-relevant applications:
- Tracking error is a norm of an affine map, so "tracking error at most 2%" is a convex (second-order cone) constraint.
- CVaR at level over scenarios is (Rockafellar–Uryasev) The bracket is jointly convex in (rules 1 to 3), so by rule 5 CVaR is convex in , and minimising it is a linear programme after introducing one slack per scenario. VaR, a quantile, is not convex in and not even subadditive; that is a structural reason risk desks optimise CVaR rather than VaR.
Worked example
convex or not?
Decide whether each is convex in (or ), naming the rule. (a) with and . (b) The logistic loss . (c) Portfolio volatility . (d) The constraint . (e) .
Show solutionHide solution
(a) Convex. A PSD quadratic, plus a linear term, plus times a norm of an affine map (rules 1 and 2). This is mean–variance with linear transaction costs.
(b) Convex. is log-sum-exp of , an atom; is affine in (rule 2); sum over (rule 1).
(c) Convex. , a norm of a linear map. Note that is convex too, but the square root of a general convex function need not be ( is concave and increasing, so rule 4 does not apply); here it works only because the result is a norm.
(d) Not convex. It is a superlevel set of a convex function: the complement of an open ellipsoid. Both and satisfy it, their midpoint does not.
(e) Concave, not convex. It is the negative of a norm. Minimising it means maximising volatility, which is unbounded or ends up at a vertex of the feasible set.
The working method is to name the atoms and the rule for each operation. If you cannot, try a counterexample with a midpoint.
Strong convexity and smoothness
Convexity says local equals global; it says nothing about speed. Two constants do:
- is -strongly convex if : it curves up at least as fast as a quadratic of curvature .
- is -smooth if is -Lipschitz, equivalently .
For twice-differentiable both together mean everywhere, and is the condition number.
Three consequences, each a two-line derivation.
- Suboptimality from the gradient. Minimise the right side of the strong-convexity inequality over (the minimiser is ): . So A small gradient is a certificate of near-optimality only when .
- Descent lemma. Put in the smoothness inequality: one gradient step of size lowers by at least .
- Linear convergence. Combine the two: , so This is the general (non-quadratic) version of the quadratic rate in the gradient-descent lesson.
Without strong convexity (), gradient descent still converges but only sublinearly, , and the minimiser may be non-unique or may not exist at all: logistic regression on linearly separable data is convex but its infimum is approached only as .
Regularisation is the standard fix. Adding adds to every Hessian eigenvalue, so and . Lasso's penalty does not add strong convexity (it is piecewise linear), which is why lasso solutions can be non-unique when and why the elastic net adds a small ridge term.
Worked example
what ridge buys an optimiser
A least-squares problem has Hessian eigenvalues between and . Compare gradient descent with step on the raw problem and with a ridge penalty : how many steps does the bound need to reach a reduction in suboptimality? On the ridge problem, a solver stops with . What can you guarantee?
Show solutionHide solution
Raw: , , . Steps: .
Ridge: , , . Steps: , about four times fewer.
Certificate: with ,
The same gradient norm on the raw problem only guarantees and a distance of . A stopping rule based on gradient norm is only meaningful once you know (or bound) .
The statistical side is separate: ridge changes the estimator (adds bias, cuts variance). The optimisation side is that it makes every algorithm faster and the solution unique.
Recognising convex formulations
| Problem | Convex form | Class |
|---|---|---|
| OLS, ridge | unconstrained QP | |
| Lasso | QP after splitting | |
| Quantile / LAD regression | LP | |
| Logistic regression | log-sum-exp of affine maps | smooth convex |
| Minimum variance, mean–variance | , linear constraints | QP |
| Tracking-error or volatility limit | SOCP | |
| Minimum CVaR | Rockafellar–Uryasev with scenario slacks | LP |
| Maximum Sharpe ratio | change of variables (below) | QP |
| Risk parity | (below) | smooth strictly convex |
| Cardinality, lot sizes, VaR | none in general | mixed-integer / nonconvex |
The classes nest, LP QP SOCP SDP, and each has interior-point methods that solve to high accuracy in a few dozen iterations, each costing a linear solve. When you can name the class, you can name the solver.
Maximum Sharpe. The ratio is not concave, but it is quasi-concave: for its superlevel set is a convex cone. It is also scale-invariant, so fix the numerator instead of the denominator: solve
then set . This is a convex QP, valid whenever some portfolio has positive expected excess return.
Risk parity. Equal risk contributions look like a system of nonlinear equations. But the stationarity condition of the strictly convex problem is , i.e. : risk contributions proportional to the budgets . Normalising preserves the proportions, so the unique long-only risk-budgeting portfolio is the solution of a convex problem.
import numpy as np
from scipy.optimize import minimize
vol = np.array([0.10, 0.20, 0.30])
corr = np.array([[1.0, 0.2, 0.4], [0.2, 1.0, 0.5], [0.4, 0.5, 1.0]])
Sigma = np.outer(vol, vol) * corr
b = np.ones(3) / 3 # equal risk budgets
def f(y):
return 0.5 * y @ Sigma @ y - b @ np.log(y)
def grad(y):
return Sigma @ y - b / y
res = minimize(f, x0=np.ones(3), jac=grad, method="L-BFGS-B", bounds=[(1e-9, None)] * 3)
w = res.x / res.x.sum()
rc = w * (Sigma @ w) / (w @ Sigma @ w) # fractional risk contributions
print("weights: ", np.round(w, 4))
print("risk shares: ", np.round(rc, 4))
print("inverse vol: ", np.round((1 / vol) / (1 / vol).sum(), 4))
weights: [0.5636 0.2715 0.1649]
risk shares: [0.3333 0.3333 0.3333]
inverse vol: [0.5455 0.2727 0.1818]
Inverse-volatility weights would be exact risk parity only if all correlations were equal; here asset 3 is more correlated with the others, so it gets less than its inverse-vol share.
Worked example
maximum Sharpe as a QP
Two assets have excess returns , volatilities and and correlation . Find the maximum-Sharpe portfolio by the convex reformulation and confirm it beats each asset alone.
Show solutionHide solution
, .
Solve s.t. . The Lagrangian condition gives :
With , the constraint fixes , and .
Normalise: . Its expected excess return is , volatility , and Sharpe ratio
Each asset alone has Sharpe ; the 50/50 mix has . The reformulation works because the Sharpe ratio is unchanged by scaling , so we may fix and minimise risk: the most return per unit of risk is the least risk per unit of return.
Knowledge check
Which of these portfolio constraint sets is NOT convex?
Knowledge check
A loss is -strongly convex. Your solver stops at a point where . What is the best guaranteed bound on ?
Knowledge check
Let be convex but able to take negative values. Which composition is guaranteed convex?
Knowledge check
Why can maximum-Sharpe be solved as a convex QP even though the Sharpe ratio is not a concave function of the weights?
Key takeaways
- Prove convexity by composition: non-negative sums, affine pre-composition, pointwise maxima, monotone composition, and partial minimisation. Disprove it with a midpoint.
- Intersections of convex sets are convex. Cardinality, minimum lot sizes, VaR limits and risk equalities are the usual convexity breakers.
- Strong convexity and smoothness give and linear convergence at rate ; without convergence is sublinear and minimisers may not be unique or exist. Ridge adds to .
- Many quant problems are convex after reformulation: tracking-error limits are SOCP, CVaR is an LP, maximum Sharpe is a QP after fixing , and risk parity is a strictly convex log-barrier problem.
Practice problems
Finished reading?
Answer the 4 knowledge checks to complete this lesson (0 done).