SDE Discretisation: Euler & Milstein#

Most models are written as a stochastic differential equation (SDE),

\[dX_t = \mu(X_t, t) \, dt + \sigma(X_t, t) \, dW_t\]

and only a few of them have a solution in closed form. For the others, the path is built one small time step at a time, and each step is an approximation. This page sets out the two standard schemes, how their errors are measured, and what goes wrong for a process that must stay positive.

Why a model becomes an SDE#

A model states how a price changes in a short time: a drift that is known, and a random part whose size may depend on the price and on time. That statement is an SDE. A local volatility model, a stochastic volatility model such as Heston and a short-rate model such as CIR are all of this form. The SDE does not give a price. It gives the paths, and the price is an average over them (Monte Carlo, Part 1: Basic Pricing).

The schemes#

Take steps of length \(h\) and write \(\Delta W = \sqrt{h} \, Z\) for the Brownian increment.

Euler-Maruyama freezes the drift and the volatility at the start of the step:

\[X_{n+1} = X_n + \mu(X_n) \, h + \sigma(X_n) \, \Delta W\]

Milstein adds the first correction that comes from the change of \(\sigma\) over the step:

\[X_{n+1} = X_n + \mu(X_n) \, h + \sigma(X_n) \, \Delta W + \tfrac{1}{2} \sigma(X_n) \, \sigma'(X_n) \left( \Delta W^2 - h \right)\]

For geometric Brownian motion \(\sigma(X) = \sigma X\), so \(\sigma \sigma' = \sigma^2 X\) and the correction is \(\tfrac{1}{2}\sigma^2 X (\Delta W^2 - h)\).

Strong and weak convergence#

There are two ways to measure the error, and they answer different questions.

  • Strong error: how close is the simulated path to the true path driven by the same random numbers? It is \(E|X_T - X_T^h|\). It matters when the whole path is used, or when a scheme is compared with another on the same numbers.

  • Weak error: how close is the simulated average to the true average? It is \(|E[f(X_T)] - E[f(X_T^h)]|\). It matters for a price, which is an average.

Orders of convergence in the step \(h\)#

Scheme

Strong order

Weak order

Euler-Maruyama

1/2

1

Milstein

1

1

Milstein gives a better path, and not a better price. For a price that depends on the terminal value only, Euler-Maruyama has the same weak order, and the extra term is of no help unless the path itself matters, for example through a barrier.

The size of the error also has a cost: halving the step doubles the work of a path. And the discretisation error is separate from the sampling error of the average, which falls with the number of paths. A price needs both to be small.

Positive processes#

For a square-root process such as CIR, an Euler step can give a negative value, and then \(\sqrt{v}\) is undefined. Common repairs are full truncation, which uses \(\max(v, 0)\) in the drift and the volatility, and reflection, which takes the absolute value. Both bias the result a little. The exact non-central chi-squared draw of Stochastic Processes, or the quadratic-exponential scheme of Andersen, avoid the problem. The bias is larger when the Feller condition fails.

Worked example#

The example takes 400,000 paths of geometric Brownian motion and builds the terminal value with 1 to 32 steps, from the same Brownian increments, by each scheme. The exact solution on the same increments is the reference, so the errors are measured path by path. It also counts negative variances for a CIR process under Euler.

Python code
"""Euler-Maruyama and Milstein for geometric Brownian motion: strong and weak convergence against the exact solution."""
import numpy as np

from common import K, R, S0, SIGMA, T, bs_price

rng = np.random.default_rng(99)
PATHS, FINEST = 400_000, 64


def schemes(dw, dt):
    """Terminal values by Euler-Maruyama and by Milstein, from the Brownian increments dw (paths x steps)."""
    euler = np.full(dw.shape[0], S0)
    milstein = np.full(dw.shape[0], S0)
    for i in range(dw.shape[1]):
        euler = euler + R * euler * dt + SIGMA * euler * dw[:, i]
        milstein = (milstein + R * milstein * dt + SIGMA * milstein * dw[:, i]
                    + 0.5 * SIGMA**2 * milstein * (dw[:, i] ** 2 - dt))
    return euler, milstein


if __name__ == "__main__":
    fine_dt = T / FINEST
    increments = np.sqrt(fine_dt) * rng.standard_normal((PATHS, FINEST))
    exact = S0 * np.exp((R - 0.5 * SIGMA**2) * T + SIGMA * increments.sum(axis=1))
    disc = np.exp(-R * T)
    exact_price = disc * np.maximum(exact - K, 0).mean()
    print(f"Exact solution on the same {PATHS:,} paths: mean {exact.mean():.4f} (theory {S0 * np.exp(R * T):.4f}), "
          f"call {exact_price:.4f} (Black-Scholes {bs_price():.4f})\n")

    print(f"{'Steps':>6} | {'Euler strong':>13} {'mean':>10} {'call':>10} | "
          f"{'Milstein strong':>16} {'mean':>10} {'call':>10}")
    results, noise = [], None
    for steps in (1, 2, 4, 8, 16, 32):
        group = FINEST // steps
        coarse = increments.reshape(PATHS, steps, group).sum(axis=2)
        euler, milstein = schemes(coarse, T / steps)
        out = []
        for approx in (euler, milstein):
            strong = np.mean(np.abs(approx - exact))
            mean_err = np.mean(approx - exact)
            call = disc * np.mean(np.maximum(approx, K) - np.maximum(exact, K))
            out.append((strong, abs(mean_err), abs(call)))
        noise = [np.std(approx - exact) / np.sqrt(PATHS) for approx in (euler, milstein)]
        results.append(out)
        print(f"{steps:>6} | {out[0][0]:13.5f} {out[0][1]:10.5f} {out[0][2]:10.5f} | "
              f"{out[1][0]:16.5f} {out[1][1]:10.5f} {out[1][2]:10.5f}")
    print(f"Sampling noise (one standard error) in the mean and call columns at 32 steps: "
          f"Euler {noise[0]:.5f}, Milstein {noise[1]:.5f}")

    # Observed order: the slope of log2(error) as the step is halved. The weak order uses 1 to 8 steps,
    # where the error is above the sampling noise.
    first, middle, last = results[0], results[3], results[-1]
    print("\nObserved order of convergence (strong from 1 to 32 steps, weak from 1 to 8 steps):")
    print(f"  Euler:    strong {np.log2(first[0][0] / last[0][0]) / 5:.2f}, weak {np.log2(first[0][1] / middle[0][1]) / 3:.2f}")
    print(f"  Milstein: strong {np.log2(first[1][0] / last[1][0]) / 5:.2f}, weak {np.log2(first[1][1] / middle[1][1]) / 3:.2f}")

    # A square-root process: naive Euler can push the variance below zero when the Feller condition fails.
    kappa, theta, xi, v0, steps = 2.0, 0.04, 0.9, 0.04, 50
    dt = T / steps
    v = np.full(100_000, v0)
    negative = np.zeros(v.shape, dtype=bool)
    for _ in range(steps):
        v = v + kappa * (theta - v) * dt + xi * np.sqrt(np.maximum(v, 0)) * np.sqrt(dt) * rng.standard_normal(v.shape)
        negative |= v < 0
    print(f"\nCIR with xi = {xi}, 2 kappa theta = {2 * kappa * theta:.2f} against xi^2 = {xi**2:.2f}: "
          f"{negative.mean():.1%} of Euler paths went negative at some step")

The output is:

Exact solution on the same 400,000 paths: mean 103.0168 (theory 103.0455), call 9.4121 (Black-Scholes 9.4134)

 Steps |  Euler strong       mean       call |  Milstein strong       mean       call
     1 |       1.97907    0.04997    0.12952 |          0.37766    0.04497    0.20505
     2 |       1.50600    0.02579    0.03174 |          0.21823    0.02280    0.11638
     4 |       1.11116    0.01417    0.00619 |          0.12086    0.01135    0.06150
     8 |       0.80221    0.00766    0.00197 |          0.06444    0.00577    0.03159
    16 |       0.57464    0.00423    0.00016 |          0.03356    0.00281    0.01599
    32 |       0.40959    0.00097    0.00057 |          0.01717    0.00146    0.00808
Sampling noise (one standard error) in the mean and call columns at 32 steps: Euler 0.00083, Milstein 0.00004

Observed order of convergence (strong from 1 to 32 steps, weak from 1 to 8 steps):
  Euler:    strong 0.45, weak 0.90
  Milstein: strong 0.89, weak 0.99

CIR with xi = 0.9, 2 kappa theta = 0.16 against xi^2 = 0.81: 92.0% of Euler paths went negative at some step

Reading the output:

  • The strong orders are 1/2 and 1. Euler’s path error falls from 1.98 to 0.41 over five halvings, and Milstein’s from 0.38 to 0.017. The observed slopes, 0.45 and 0.89, are close to the theory.

  • The weak orders are both about 1. The error of the mean falls in proportion to the step for both schemes. At 16 and 32 steps the Euler errors in the mean and the call are inside the sampling noise of 0.0008, and cannot be read.

  • The call price error is not smaller for Milstein. It halves with each doubling of the steps, which is order 1, but it is larger than Euler’s in this case. A better path does not mean a better price. The error of the price depends on the payoff and on the scheme, and the constant is not always smaller for the higher-order scheme.

  • Even one step is not far off for a price. A single Euler step has a call error of 0.13 on 9.41, which is the effect of using a normal approximation for a lognormal variable. A model with an exact distribution should use it.

  • The CIR scheme fails when the Feller condition fails. With \(\xi = 0.9\) and \(2\kappa\theta = 0.16 < \xi^2 = 0.81\), 92% of the Euler paths went negative at some step. The price from such paths depends on the repair that is applied.

A valuation control view#

  • Measure the discretisation error and report it with the standard error: run the price at two or more step sizes. A price that moves by more than its standard error when the step is halved is not converged. See Monte Carlo, Part 1: Basic Pricing.

  • Match the scheme to the product: a terminal payoff needs the weak error to be small, and a barrier or a path-dependent payoff needs the path to be accurate. A price tested only on a European payoff says little about the barrier.

  • Use the same random numbers in a comparison: differences between two schemes, or between two implementations, are then free of sampling noise, as in the example.

  • Look at the repair for positive processes: count how often the scheme has to repair a value, and test the price against an exact or a finer simulation. Calibrated parameters that violate the Feller condition are a warning.

  • Document the step grid: the number and placement of steps is part of the model specification, and a change is a model change.

Next, The Pricing Problem & the Benchmark sets out the pricing problem and the benchmark option that the rest of the series uses.