Trading Dev AcademyFree quant education

Free lesson · Partial derivatives

Hessians, mixed derivatives and second-order scenarios

Open interactive lessonPractice calculationsExplore labs

Start with the idea

  • A straight-line estimate can miss the bend in the function. A second-order estimate also counts each input’s curvature and the interactions between inputs.
Symbols, units & horizon
  • H: Hessian matrix, not a candle high here
  • fₓₓ,fᵧᵧ: pure second partial derivatives
  • fₓᵧ,fᵧₓ: mixed second partials
  • h=(Δx,Δy): input-change vector
  • ∇f: gradient at the starting point
  • hᵀHh: quadratic form
  • Δf: output change
  • Each Hessian entry: output units divided by the two associated input units

When and why to use this

Use Hessians to inspect local curvature, compare first- and second-order scenario estimates, and understand optimisation conditioning.

Start here · the same idea in everyday words

Technical termEveryday meaningConcrete example
CurvatureHow a slope changes as its input changes.A bowl gets steeper as you move away from its centre.
HessianA table of second derivatives.Its diagonal measures each input’s own curvature; off-diagonal entries measure interactions.
Mixed derivativeHow the slope for one input changes when another input changes.A mixed x-y derivative records how the x slope responds to y.

Unpack a technical sentence

Technical wording: Second-order scenarios include curvature and cross-input interactions.

Read it as: A straight-line estimate can miss the bend in the function. A second-order estimate also counts each input’s curvature and the interactions between inputs.

A slower worked example · one step at a time

  1. Use f=x squared plus y squared, with all numbers dimensionless. At x=1 and y=2, the output is 5.
  2. The slopes are 2x=2 and 2y=4. The Hessian has diagonal values 2 and 2, and off-diagonal values zero because the two squared terms have no interaction.
  3. Increase x by .1 and y by .2. The straight-line change is 2 times .1 plus 4 times .2=1, giving a prediction of 6.
  4. The curvature correction is half of [2 times .1 squared plus 2 times .2 squared]=.05. The second-order prediction is 6.05.
  5. Direct evaluation gives 1.1 squared plus 2.2 squared=6.05. The second-order answer is exact here because the function is quadratic. A general curved function can still have higher-order error.
Self-assessed: Does a second-order approximation always give the exact answer?

No. It is exact for this quadratic. More general smooth functions can have third- and higher-order contributions.

  • For a function with continuous second partials in a neighbourhood, mixed partial derivatives agree.
  • Without the regularity assumptions that symmetry cannot simply be assumed.
  • A Hessian is local, just like a gradient.
  • The second-order multivariable Taylor term is one half of a quadratic form in the input changes.
  • Off-diagonal terms appear twice in the full sum, so the two-variable cross contribution has no remaining one-half factor when the Hessian is symmetric.
H=(fxxfxyfyxfyy),Δf≈∇f𝖳h+12h𝖳Hh
Calculus: derivation and arithmetic

Hessians, mixed derivatives and second-order scenarios

  1. For f=x²+xy+2y², compute fₓ=2x+y and fᵧ=x+4y. Differentiate again to obtain H=[[2,1],[1,4]].
  2. Expand hᵀHh=2(Δx)²+2ΔxΔy+4(Δy)². Multiplying by one half gives the curvature correction.
  3. At (1,1), gradient=(3,5). With h=(.1,−.2), the linear term is −.7. Curvature is .01−.02+.08=.07, giving total −.63.
Work it by hand

Original value f(1,1)=4. New value f(1.1,.8)=3.37. The change is exactly −.63 because this function is quadratic and has no higher-order remainder.

Architecture pseudocode

def quadratic_value(x,y): return x*x+x*y+2*y*y

def quadratic_change(x,y,dx,dy):
    linear=(2*x+y)*dx+(x+4*y)*dy
    curvature=dx*dx+dx*dy+2*dy*dy
    return linear,curvature,linear+curvature

print(quadratic_change(1,1,.1,-.2),quadratic_value(1.1,.8)-quadratic_value(1,1))

# Replay the slower, synthetic example above. Units are stated in its steps.
def plain_language_example():
    from math import exp, e  # Standard library; no extra dependency.
    return {
        "start": 1**2+2**2,
        "linear": 5+2*.1+4*.2,
        "correction": .5*(2*.1**2+2*.2**2),
        "actual": 1.1**2+2.2**2,
    }

print(plain_language_example())

An analogy to remember

Bending a sheet in two directions can create an interaction that neither one-direction bend captures. Mixed derivatives quantify that local interaction.

How this becomes a building block

Gamma is one entry of a pricing Hessian. Cross sensitivities such as spot–volatility interaction can matter in a joint market shock. In portfolio optimisation, the covariance quadratic form supplies curvature of a mean–variance objective.

Python implementation

Self-contained teaching example. Python 3.10+; dependencies and input conventions are shown in the code and notation. Run in your own Python environment.

def quadratic_value(x,y): return x*x+x*y+2*y*y

def quadratic_change(x,y,dx,dy):
    linear=(2*x+y)*dx+(x+4*y)*dy
    curvature=dx*dx+dx*dy+2*dy*dy
    return linear,curvature,linear+curvature

print(quadratic_change(1,1,.1,-.2),quadratic_value(1.1,.8)-quadratic_value(1,1))

# Replay the slower, synthetic example above. Units are stated in its steps.
def plain_language_example():
    from math import exp, e  # Standard library; no extra dependency.
    return {
        "start": 1**2+2**2,
        "linear": 5+2*.1+4*.2,
        "correction": .5*(2*.1**2+2*.2**2),
        "actual": 1.1**2+2.2**2,
    }

print(plain_language_example())

Continue learning

Multivariable Calculus & Partial Derivatives — all lessons
  1. Start with two inputs: change only one
  2. Partial derivatives: holding the other inputs fixed
  3. Gradients, directional derivatives and Jacobians
  4. Hessians, mixed derivatives and second-order scenarios
  5. Constrained optimisation and multiple integrals

Quantitative finance and development glossary · Python resources and libraries · Research sources and limitations