Trading Dev AcademyFree quant education

Free lesson · Differential calculus

Second derivatives, Taylor expansions and numerical error

Open interactive lessonPractice calculationsExplore labs

Start with the idea

  • The first derivative tells you the local slope.
  • The second derivative tells you how that slope changes.
  • Adding curvature to a tangent approximation explains why a straight-line estimate misses curved behaviour.
Symbols, units & horizon
  • f′,f″: first and second derivatives
  • h: input change or finite-difference step
  • R₃: omitted third-and-higher-order contribution
  • M: bound on absolute third derivative for the stated error bound
  • |h|: step magnitude
  • ≈: approximate equality
  • 2h: distance between the two symmetric sample points

When and why to use this

Use curvature to improve a local approximation and to understand when numerical derivatives are trustworthy. Compare several step sizes, especially when evaluating a noisy simulation.

  • A second derivative is obtained by differentiating the first derivative.
  • A positive second derivative describes local upward curvature; it does not necessarily mean the function itself is increasing.
  • For example, x² is convex even where its slope is negative.
  • A Taylor expansion is a local approximation with a remainder.
  • If a third derivative is bounded by M across the relevant interval, the second-order remainder is bounded by M|h|³/6.
  • Without such regularity or a sufficiently small step, the approximation may be poor.
f(x+h)=f(x)+f′(x)h+12f′′(x)h2+R3,f′(x)≈f(x+h)−f(x−h)2h
Calculus: derivation and arithmetic

Second derivatives, Taylor expansions and numerical error

  1. Match the value, slope and curvature with a quadratic in h: coefficients are f(x), f′(x) and f″(x)/2 because the second derivative of h² is 2.
  2. Write Taylor expansions at +h and −h. Subtracting cancels f(x) and the even powers. Dividing by 2h gives the central derivative formula with an error of order h² for a sufficiently smooth function.
  3. For f(x)=x³ at x=2, f=8, f′=12, f″=12. At h=.1 the quadratic estimate is 8+1.2+.06=9.26; the omitted cubic is .001.
Work it by hand

The exact value 2.1³ is 9.261. The central slope at x=2 with h=.1 is (2.1³−1.9³)/.2=12.01, compared with the exact derivative 12.

An analogy to remember

A tangent is a straight ruler touching a bend in a road. A quadratic approximation also matches how tightly the road bends, but neither tells you the route far away.

How this becomes a building block

Delta and gamma are the first two spot derivatives in an option P&L approximation. Duration and convexity play a related role for bond price versus yield. Taylor expansions also explain truncation error in simulation and finite-difference solvers.

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 taylor2(value, first, second, step):
    return value+first*step+.5*second*step**2

def central_derivative(function,x,h):
    if h<=0: raise ValueError("Positive step required")
    return (function(x+h)-function(x-h))/(2*h)

def central_second(function,x,h):
    if h<=0: raise ValueError("Positive step required")
    return (function(x+h)-2*function(x)+function(x-h))/h**2

print(taylor2(8,12,12,.1),central_derivative(lambda x:x**3,2,.1))

Continue learning

Differential Calculus: Limits & Derivatives — all lessons
  1. Start with a straight line: input, output and slope
  2. Functions, limits and continuity
  3. The derivative: from an average slope to an instantaneous rate
  4. Core derivative rules: constants, powers and sums
  5. Derivative rules: powers, products, quotients and compositions
  6. Second derivatives, Taylor expansions and numerical error
  7. Stationary points, optimisation and Newton’s method

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