PDE Methods, Part 2: Implicit & Crank-Nicolson#

The explicit scheme of PDE Methods, Part 1: The Black-Scholes PDE & the Explicit Scheme is stable only if the time step is tiny compared with the square of the space step. The implicit scheme removes that limit, at the price of solving a system of equations at every step, and Crank-Nicolson is more accurate still. But Crank-Nicolson has a weakness that matters for option payoffs, and a remedy. This is the second of three pages on PDE methods.

The implicit scheme#

Evaluate the space differences at the new time level. Writing \(L\) for the space operator, the step is

\[\left( I - \Delta\tau \, L \right) V^{n+1} = V^n\]

The left side is a tridiagonal matrix: each row involves a node and its two neighbours. The system is solved in a number of operations proportional to \(M\), with the Thomas algorithm (Numerical Linear Algebra), so an implicit step costs only a few times an explicit one. The scheme is stable for any time step. The price is a lower accuracy in time, first order.

Crank-Nicolson#

Take the average of the explicit and the implicit schemes, a theta scheme with \(\theta = 1/2\):

\[\left( I - \tfrac{1}{2}\Delta\tau \, L \right) V^{n+1} = \left( I + \tfrac{1}{2}\Delta\tau \, L \right) V^n\]

It is stable and second order in time. For a smooth problem it is the standard choice. For an option payoff, which has a kink at the strike, it has a flaw. Crank-Nicolson does not damp the high-frequency components of the initial data, and the kink contains all frequencies. Those components decay only slowly, and they show up as oscillations near the strike, especially in the gamma and the delta. The convergence of the price at the strike falls to first order.

Rannacher smoothing#

The remedy is to start with a few fully implicit steps, which do damp the high frequencies, and then to switch to Crank-Nicolson. Each of the first steps is split into two half steps to keep the accuracy. Two such steps are usually enough. This restores second-order convergence and removes the oscillation, at almost no cost.

Greeks from the grid#

The delta and the gamma come from the grid by differences of the values at neighbouring nodes. They have the same accuracy as the price, and smoothness that Monte Carlo cannot give. This is a main strength of the PDE method, and it is why the oscillation of Crank-Nicolson matters: a price may be right while the gamma is not.

Worked example#

The example solves the benchmark call by the implicit and Crank-Nicolson schemes with few time steps, measures the order of convergence in time with and without Rannacher smoothing, and then prices a call with a strike between two grid nodes, where the kink is not on the grid, and compares the price, delta and gamma.

Python code
"""Implicit and Crank-Nicolson finite differences for the Black-Scholes PDE, with Rannacher smoothing and Greeks from the grid."""
import numpy as np
from scipy.linalg import solve_banded

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


def operator(m, dx):
    """Lower, diagonal and upper coefficients of the space operator L V = 0.5 s^2 V_xx + mu V_x - r V."""
    mu = R - 0.5 * SIGMA**2
    lower = np.full(m + 1, 0.5 * SIGMA**2 / dx**2 - 0.5 * mu / dx)
    diag = np.full(m + 1, -SIGMA**2 / dx**2 - R)
    upper = np.full(m + 1, 0.5 * SIGMA**2 / dx**2 + 0.5 * mu / dx)
    return lower, diag, upper


def apply(v, lower, diag, upper):
    out = np.zeros_like(v)
    out[1:-1] = lower[1:-1] * v[:-2] + diag[1:-1] * v[1:-1] + upper[1:-1] * v[2:]
    return out


def solve_call(m, n, theta=0.5, strike=K, rannacher=0, half_width=1.0):
    """Value of a call on the grid, with theta = 1 for implicit and 0.5 for Crank-Nicolson.

    The first `rannacher` steps are taken as two implicit half steps each, which smooths the kink in the payoff.
    Returns the log-price grid and the values.
    """
    dx, dt = 2 * half_width / m, T / n
    x = np.log(S0) + np.linspace(-half_width, half_width, m + 1)
    s = np.exp(x)
    lower, diag, upper = operator(m, dx)
    v = np.maximum(s - strike, 0)

    def step(v, dt_step, th, tau):
        ab = np.zeros((3, m + 1))
        ab[0, 1:] = -th * dt_step * upper[:-1]
        ab[1] = 1 - th * dt_step * diag
        ab[2, :-1] = -th * dt_step * lower[1:]
        rhs = v + (1 - th) * dt_step * apply(v, lower, diag, upper)
        ab[1, 0] = ab[1, -1] = 1.0
        ab[0, 1] = 0.0
        ab[2, -2] = 0.0
        rhs[0], rhs[-1] = 0.0, s[-1] - strike * np.exp(-R * tau)
        return solve_banded((1, 1), ab, rhs)

    tau = 0.0
    for i in range(n):
        if i < rannacher:
            for _ in range(2):
                tau += dt / 2
                v = step(v, dt / 2, 1.0, tau)
        else:
            tau += dt
            v = step(v, dt, theta, tau)
    return x, v


def price_and_greeks(x, v):
    """Price, delta and gamma at S0 from the grid. The grid is centred on S0."""
    j = (len(x) - 1) // 2
    dx = x[1] - x[0]
    vx = (v[j + 1] - v[j - 1]) / (2 * dx)
    vxx = (v[j + 1] - 2 * v[j] + v[j - 1]) / dx**2
    return v[j], vx / S0, (vxx - vx) / S0**2


if __name__ == "__main__":
    exact = bs_price()
    print(f"Black-Scholes call {exact:.6f}\n")
    print("200 space intervals, few time steps: implicit and Crank-Nicolson stay stable where the explicit scheme blows up")
    print(f"{'Time steps':>11} {'Implicit error':>15} {'Crank-Nicolson error':>21}")
    for n in (5, 10, 25, 50, 100, 200):
        e_imp = price_and_greeks(*solve_call(200, n, theta=1.0))[0] - exact
        e_cn = price_and_greeks(*solve_call(200, n, theta=0.5))[0] - exact
        print(f"{n:>11} {e_imp:+15.6f} {e_cn:+21.6f}")

    print("\nOrder in time, with 4000 space intervals so that the space error is small")
    print(f"{'Time steps':>11} {'Implicit':>10} {'Ratio':>6} {'Crank-Nicolson':>15} {'Ratio':>6} {'CN + Rannacher':>15} {'Ratio':>6}")
    prev = [None, None, None]
    for n in (10, 20, 40, 80):
        errs = [price_and_greeks(*solve_call(4000, n, theta=th, rannacher=ran))[0] - exact
                for th, ran in ((1.0, 0), (0.5, 0), (0.5, 2))]
        ratios = ["" if p is None else f"{p / e:6.2f}" for p, e in zip(prev, errs)]
        print(f"{n:>11} {errs[0]:+10.6f} {ratios[0]:>6} {errs[1]:+15.6f} {ratios[1]:>6} {errs[2]:+15.6f} {ratios[2]:>6}")
        prev = errs

    # A strike between grid nodes: the kink is smoothed badly, and the Greeks from Crank-Nicolson oscillate.
    strike = 103.3
    ex_p = bs_price(k=strike)
    ex_d, ex_g, _ = bs_greeks(k=strike)
    print(f"\nStrike {strike}, which is between nodes. Black-Scholes price {ex_p:.6f}, delta {ex_d:.6f}, gamma {ex_g:.6f}")
    print("200 space intervals, 25 time steps")
    print(f"{'Scheme':<30} {'Price error':>12} {'Delta error':>12} {'Gamma error':>12}")
    for name, th, ran in (("Implicit", 1.0, 0), ("Crank-Nicolson", 0.5, 0), ("Crank-Nicolson + Rannacher", 0.5, 2)):
        p, d, g = price_and_greeks(*solve_call(200, 25, theta=th, strike=strike, rannacher=ran))
        print(f"{name:<30} {p - ex_p:+12.6f} {d - ex_d:+12.6f} {g - ex_g:+12.6f}")

The output is:

Black-Scholes call 9.413403

200 space intervals, few time steps: implicit and Crank-Nicolson stay stable where the explicit scheme blows up
 Time steps  Implicit error  Crank-Nicolson error
          5       -0.206715             +0.357215
         10       -0.105288             -0.120486
         25       -0.043691             +0.001535
         50       -0.023046             -0.002247
        100       -0.012703             -0.002322
        200       -0.007527             -0.002341

Order in time, with 4000 space intervals so that the space error is small
 Time steps   Implicit  Ratio  Crank-Nicolson  Ratio  CN + Rannacher  Ratio
         10  -0.102846              -0.196422              -0.007899
         20  -0.051603   1.99       -0.098579   1.99       -0.001970   4.01
         40  -0.025847   2.00       -0.048725   2.02       -0.000496   3.97
         80  -0.012937   2.00       -0.022983   2.12       -0.000128   3.86

Strike 103.3, which is between nodes. Black-Scholes price 7.852499, delta 0.534928, gamma 0.019871
200 space intervals, 25 time steps
Scheme                          Price error  Delta error  Gamma error
Implicit                          -0.039843    -0.001478    +0.000301
Crank-Nicolson                    -0.000216    +0.000534    +0.000906
Crank-Nicolson + Rannacher        -0.001715    -0.000005    +0.000008
Gamma across the grid for Crank-Nicolson, with and without Rannacher steps, against the exact Black-Scholes gamma

Reading the output:

  • Both schemes stay stable with only five time steps, where the explicit scheme gave a price of \(10^{64}\) or worse. Stability is no longer the constraint, and accuracy is.

  • The implicit scheme is first order. The error halves each time the steps double, a ratio of 2.0.

  • Raw Crank-Nicolson is also first order here, with a ratio of 2.0, and its error is larger than the implicit one at the same steps. The kink on a node has spoiled the second-order accuracy. With Rannacher smoothing the ratio is about 4, and the error at 80 steps is 0.00013, about 180 times smaller than raw Crank-Nicolson, 0.023.

  • The Greeks show the oscillation. With the strike between nodes, raw Crank-Nicolson has a gamma error of 0.0009, which is 4.6% of the gamma of 0.0199, and the figure shows the gamma swinging above and below the true curve. With Rannacher steps the gamma error is 0.000008, 100 times smaller, and the delta error is 0.000005. The price error is larger with Rannacher, -0.0017 against -0.0002. The price is not a good test of the Greeks.

A valuation control view#

  • Test Greeks as well as prices: a scheme can price well and give a gamma with oscillations. The gamma is the quantity that drives the risk of an option book, and a noisy gamma shows up as noise in the hedge.

  • Use Rannacher or an equivalent for payoffs with kinks and jumps: and check that it is switched on. A library default of plain Crank-Nicolson is a common finding in a model review.

  • Test the strike off the grid: an engine tested only with the strike on a node, as in the first tests above, has hidden the problem. Moving the strike by a fraction of a node is a cheap test.

  • Look at the order of convergence, not only the size of the error: a ratio of 2 where 4 is expected means that the scheme has fallen to first order, because of the payoff, the boundary or a bug.

  • Choose the time step for the accuracy that is needed: an implicit scheme is stable at any step, so a coarse step can give a stable and poor price. Stability is not accuracy.

Next, PDE Methods, Part 3: American Options & Trees vs Finite Differences adds early exercise, and compares finite differences with trees.