Skip to content
Module 04 of 1050 min readAdvanced

Numerical integration

Trapezoid, Simpson, Gauss-Hermite, Gauss-Legendre. Pricing a European option by integrating the risk-neutral density.

40%

Listen along

Read “Numerical integration” aloud

Plays in your browser using on-device text-to-speech — nothing leaves the page.

Numerical integration (quadrature) approximates definite integrals. In finance: pricing European options as expectations under the risk-neutral density, computing CVaR as tail integrals, calibrating models that involve integral transforms (characteristic-function methods like Heston/COS).

Trapezoidal rule

math
∫_a^b f(x) dx ≈ (Δx) [f(a)/2 + f(x_1) + ... + f(x_{n-1}) + f(b)/2]

Equally-spaced nodes; piecewise-linear approximation. Error decays as O(1/n²). Simple, robust.

Simpson's rule

math
∫_a^b f(x) dx ≈ (Δx/3) [f(a) + 4 f(x_1) + 2 f(x_2) + 4 f(x_3) + ... + f(b)]

Equally-spaced nodes; piecewise-quadratic approximation. Error decays as O(1/n⁴). Standard default for smooth integrands.

Gauss-Legendre quadrature

math
∫_{-1}^1 f(x) dx ≈ Σ_{i=1}^n w_i f(x_i)

Cleverly chosen nodes (roots of Legendre polynomial) and weights (analytically derived) maximise the polynomial degree the rule integrates exactly. n-point Gauss-Legendre integrates polynomials of degree 2n-1 exactly — twice the accuracy of equally-spaced rules. Use scipy.special.roots_legendre to get nodes and weights.

Gauss-Hermite quadrature

Quadrature for ∫_{-∞}^∞ exp(-x²) f(x) dx. Used for computing expectations under normal distributions — option pricing under Gaussian densities, MLE of regression with Gaussian errors. The natural choice for any integral with a Gaussian weight.

Adaptive quadrature

Subdivide the integration domain into pieces, applying high-accuracy rules in each, with finer subdivision where the integrand is more rugged. scipy.integrate.quad uses adaptive Gauss-Kronrod and is the default for general integration in Python. Robust for smooth integrands with localised features.

Pricing a European option by quadrature

Under Black-Scholes, S(T) is lognormal. Call price:

math
C = e^{-rT} ∫_K^∞ (S - K) f_{S(T)}(S) dS

Substitute u = log S to integrate against the Gaussian density of log S(T) — a 1D integral, easily computed by Gauss-Hermite or Simpson. For BS this is overkill (closed form exists), but for stochastic-vol models with non-Gaussian densities (e.g., Heston) it is the standard method.

Characteristic-function methods

Many advanced models (Heston, Variance Gamma, jump-diffusion) have closed-form characteristic functions but no closed-form densities. The COS method (Fang-Oosterlee 2008) and the Carr-Madan FFT method express the option price as an inverse Fourier transform of the characteristic function, computed by FFT or COS quadrature. Industry-standard for stochastic-vol option pricing.

Higher-dimensional integration

Quadrature rules suffer from the curse of dimensionality: n-point quadrature in d dimensions costs n^d evaluations. For d ≥ 4 or so, Monte Carlo wins. We cover Monte Carlo in detail in Modules 6-7.

Exercise

Use Simpson's rule with 4 intervals to estimate ∫_0^1 e^x dx. (1) Compute the approximation. (2) Compare to the exact value e - 1 ≈ 1.7183. (3) What is the relative error?

Loading progress…
LeadAfrikPublic Economics Hub