The two derivatives that matter
For , the gradient is the vector of partial derivatives: it points uphill, and . The Hessian is the symmetric matrix of second partials, and it gives the curvature:
At a critical point () the linear term vanishes, so the shape of nearby is the shape of the quadratic form . Classifying optima is therefore a question about the definiteness of , which is linear algebra you already know.
Objective: differentiate the quadratic expressions that appear in quant work without writing out components, classify critical points, recognise convex problems, and take a Newton step.
Matrix calculus you need
With a constant vector and a constant matrix:
| , symmetric | ||
| (in ) |
Sanity-check the quadratic form in one dimension: has derivative .
Least squares. Setting the gradient to zero gives the normal equations
The first-order condition says : residuals are orthogonal to every column of . With an intercept column, residuals sum to zero. The Hessian is PSD (since ), so this critical point is a global minimum; it is PD, and the minimum unique, exactly when has full column rank.
Portfolio variance. . Component , , is the marginal variance of adding a little of asset ; the risk contributions sum to the total variance.
Definiteness tests and the second-derivative test
For symmetric :
| is | Means | Test |
|---|---|---|
| positive definite | for | all eigenvalues ; or all leading principal minors (Sylvester); or Cholesky succeeds |
| positive semi-definite | all eigenvalues ; or all principal minors | |
| negative definite | is PD | leading minors alternate in sign, starting negative |
| indefinite | takes both signs | some eigenvalue positive and some negative |
For : is PD iff and . A negative determinant means indefinite, whatever the diagonal.
At a critical point: PD gives a strict local minimum, ND a strict local maximum, indefinite a saddle. If is only semi-definite the test is inconclusive: and both have at the origin.
A trap for PSD: leading minors are not enough. has leading minors and but is not PSD.
Worked example
classifying critical points
Find and classify the critical points of .
Show solutionHide solution
, which vanishes at and .
At : is PD, a local minimum with .
At : is indefinite, a saddle: a maximum along , a minimum along .
The local minimum is not global: as . Nothing about a PD Hessian at one point says anything about the rest of the domain. That is what convexity adds.
Convexity: why local equals global
is convex if the chord lies above the graph:
Equivalent conditions for smooth : the tangent plane lies below the graph, ; or the Hessian is PSD everywhere.
Local implies global. Suppose is a local minimum and some had . Points on the segment, , satisfy for every , including tiny, i.e. arbitrarily close to . That contradicts being a local minimum. Also, from the tangent-plane inequality, any point with is a global minimum. Strict convexity (for example, PD everywhere) makes the minimiser unique.
Convex building blocks: , with PSD, any norm, , , , and non-negative sums and pointwise maxima of convex functions. Least squares, ridge, lasso, logistic regression and minimum-variance portfolios are all convex problems. Mean–variance utility is concave, so maximising it is the same thing. Neural network losses and most calibration objectives are not convex, which is why they have local minima and starting-point dependence.
A feasible set also has to be convex for "local = global" to hold for a constrained problem: linear constraints and budget constraints are fine, a cardinality constraint ("at most 10 names") is not.
Worked example
a least-squares line via the gradient
Fit to the points by least squares, and confirm the solution is a global minimum.
Show solutionHide solution
With design matrix having columns and :
, so
Residuals: . They sum to zero and , as the first-order conditions require. The residual sum of squares is .
The Hessian has diagonal and determinant , so it is PD at every point: the objective is strictly convex and is the unique global minimum.
Newton's method and gradient descent
Minimise the local quadratic model: setting the gradient of to zero gives the Newton step
(Solve with a Cholesky; do not invert.) Properties worth saying in an interview:
- On a quadratic with PD, one step lands exactly on the minimiser from anywhere.
- Near a minimum with PD Hessian, convergence is quadratic: the error roughly squares each step, so the number of correct digits doubles.
- Far from the minimum, or where is not PD, the step can go uphill or diverge. Practical versions add a line search or a damping term .
- Each step costs a Hessian and an solve; quasi-Newton methods (BFGS) build an approximation from gradients instead.
Newton for root-finding () is the same idea applied to : that is how implied volatility is usually solved, with vega as the derivative.
Gradient descent uses no curvature. On a quadratic with Hessian eigenvalues , each eigen-direction is multiplied by per step, so it converges iff , and even the best fixed step, , shrinks the error only by per step. Ill-conditioning makes gradient descent slow; Newton is unaffected by it.
Worked example
quadratic convergence of Newton's method
Minimise with Newton's method from .
Show solutionHide solution
and , so is strictly convex with unique minimiser . The Newton update is
import math
x = 0.0
for k in range(1, 6):
x = x - (math.exp(x) - 2) / math.exp(x) # x - f'(x) / f''(x)
print(k, f"{x:.10f}", f"{abs(x - math.log(2)):.1e}")
1 1.0000000000 3.1e-01
2 0.7357588823 4.3e-02
3 0.6940422999 9.0e-04
4 0.6931475811 4.0e-07
5 0.6931471806 8.0e-14
The error goes : each is roughly half the square of the last (the constant is here). Compare gradient descent on , where : with the optimal fixed step the error shrinks by only per step, and cutting it by a factor of 100 takes 231 steps.
Knowledge check
What kind of critical point does have at the origin?
Knowledge check
You run fixed-step gradient descent on a quadratic whose Hessian has eigenvalues 1 and 100. Above what step size does it diverge?
Knowledge check
Which function of a real variable is NOT convex on its domain?
Knowledge check
How many Newton steps does it take to minimise , with positive definite, from an arbitrary start?
Key takeaways
- and for symmetric . Least squares gives the normal equations : residuals orthogonal to the regressors.
- At a critical point: Hessian PD means minimum, ND maximum, indefinite saddle, semi-definite inconclusive. For , a negative determinant means saddle.
- Convex (Hessian PSD everywhere, convex feasible set) means every local minimum is global, and a zero gradient certifies it.
- Newton, , is exact in one step on quadratics and converges quadratically near a minimum. Gradient descent needs and slows with the condition number.
Practice problems
Finished reading?
Answer the 4 knowledge checks to complete this lesson (0 done).