PDE Methods, Part 1: The Black-Scholes PDE & the Explicit Scheme#
A tree builds the price from a random walk. A finite difference method solves the differential equation that the price satisfies. It works on a grid of stock prices and times, it gives smooth Greeks, and it handles early exercise and barriers well, at the cost of choosing the grid. This is the first of three pages on PDE methods. It sets up the equation and solves it with the simplest scheme, which shows, by failing, why the stability of a scheme matters.
From the model to the PDE#
For a payoff \(g(S_T)\) and the dynamics of The Pricing Problem & the Benchmark, the value \(V(S, t)\) satisfies the Black-Scholes equation. It is easier to solve in the time to expiry \(\tau = T - t\), since the problem then starts from the payoff and runs forward in \(\tau\), and in the log price \(x = \ln S\), since the coefficients become constants:
The three terms are diffusion, drift and discounting. The equation is the same as the pricing expectation (the Feynman-Kac result of The Pricing Problem & the Benchmark), written as a differential equation.
The grid#
Choose a range \([x_{\min}, x_{\max}]\) that covers the prices that matter, with \(M\) intervals of width \(\Delta x\), and \(N\) time steps of length \(\Delta\tau\). Replace the derivatives by differences at node \(j\):
Boundary conditions close the problem at the ends of the range. For a call, the value is 0 at the low end, and \(S - K e^{-r\tau}\) at the high end. The range has to be wide enough that the boundary does not affect the price at the spot: five standard deviations of the log price on each side is a common choice. An unsuitable boundary is one of the most common sources of error in a PDE price.
The explicit scheme#
The explicit scheme evaluates the space differences at the old time level and steps forward:
with weights that depend on the ratio \(\rho = \sigma^2 \Delta\tau / \Delta x^2\):
Each step is a short loop, with no linear system to solve, and the scheme is simple to code and to check. Its weakness is stability.
Stability#
An error introduced at one step is multiplied by the scheme at every later step. The scheme is stable if the error does not grow. For the explicit scheme this holds only if \(\rho \le 1\), which is \(\Delta\tau \le \Delta x^2/\sigma^2\). If \(\rho\) is larger, the middle weight \(p_m\) becomes negative, and the highest-frequency errors are amplified at each step. The result is not a bad price. It is an explosion.
The condition links the two grids: halving \(\Delta x\) forces four times as many time steps. The cost grows with the cube of the space refinement in one dimension.
Worked example#
The example runs the explicit scheme on the benchmark call with 200 space intervals and 100 to 4,000 time steps, to show the stability limit, and then refines the grid with the ratio held at 0.8 to measure the order. It finally compares the scheme with the trinomial tree of Lattice Methods, Part 2: Trinomial Trees & Early Exercise on the same lattice.
Python code
"""Explicit finite differences for the Black-Scholes PDE in log price: convergence, the stability limit, and the link to a trinomial tree."""
import numpy as np
from common import K, R, S0, SIGMA, T, bs_price
from trinomial_example import LAMBDA, trinomial
def explicit_call(m, n, half_width=1.0):
"""Explicit scheme on x = ln S, m space intervals and n time steps. Returns the price at S0 and the ratio sigma^2 dt / dx^2."""
dx, dt = 2 * half_width / m, T / n
x = np.log(S0) + np.linspace(-half_width, half_width, m + 1)
s = np.exp(x)
mu = R - 0.5 * SIGMA**2
ratio = SIGMA**2 * dt / dx**2
pu = 0.5 * ratio + 0.5 * mu * dt / dx
pd = 0.5 * ratio - 0.5 * mu * dt / dx
pm = 1 - ratio - R * dt
v = np.maximum(s - K, 0)
for step in range(1, n + 1):
tau = step * dt
v[1:-1] = pd * v[:-2] + pm * v[1:-1] + pu * v[2:]
v[0], v[-1] = 0.0, s[-1] - K * np.exp(-R * tau)
return v[m // 2], ratio
if __name__ == "__main__":
exact = bs_price()
print(f"Black-Scholes call {exact:.6f}\n")
print("Stability: 200 space intervals (dx = 0.01), more and more time steps")
print(f"{'Time steps':>11} {'sigma^2 dt/dx^2':>16} {'Price':>14}")
for n in (100, 200, 300, 400, 500, 1000, 4000):
price, ratio = explicit_call(200, n)
print(f"{n:>11} {ratio:16.3f} {price:14.6g}")
print("\nConvergence with the ratio fixed at 0.8: halving dx means four times the time steps")
print(f"{'Intervals':>10} {'Time steps':>11} {'Price':>10} {'Error':>11} {'Ratio of errors':>16}")
previous = None
for m in (50, 100, 200, 400, 800):
dx = 2.0 / m
n = int(np.ceil(SIGMA**2 * T / (0.8 * dx**2)))
price, _ = explicit_call(m, n)
err = price - exact
print(f"{m:>10} {n:>11} {price:10.6f} {err:+11.6f} {'' if previous is None else f'{previous / err:16.2f}'}")
previous = err
# The explicit scheme is a trinomial tree: the same lattice, with the discounting done slightly differently.
print("\nExplicit scheme on the trinomial lattice (dx = lambda sigma sqrt(dt), lambda^2 = 1.5), against the tree")
print(f"{'Steps':>6} {'Explicit FD':>12} {'Trinomial tree':>15} {'Difference':>11}")
for n in (50, 100, 200, 400):
dt = T / n
dx = LAMBDA * SIGMA * np.sqrt(dt)
fd, _ = explicit_call(2 * n, n, half_width=n * dx)
tree = trinomial(n)
print(f"{n:>6} {fd:12.6f} {tree:15.6f} {fd - tree:+11.6f}")
The output is:
Black-Scholes call 9.413403
Stability: 200 space intervals (dx = 0.01), more and more time steps
Time steps sigma^2 dt/dx^2 Price
100 4.000 -4.29715e+82
200 2.000 -2.31848e+93
300 1.333 -2.34964e+64
400 1.000 9.40851
500 0.800 9.41313
1000 0.400 9.41209
4000 0.100 9.41131
Convergence with the ratio fixed at 0.8: halving dx means four times the time steps
Intervals Time steps Price Error Ratio of errors
50 32 9.408466 -0.004937
100 126 9.412251 -0.001153 4.28
200 501 9.413124 -0.000279 4.13
400 2001 9.413334 -0.000069 4.03
800 8001 9.413386 -0.000017 4.01
Explicit scheme on the trinomial lattice (dx = lambda sigma sqrt(dt), lambda^2 = 1.5), against the tree
Steps Explicit FD Trinomial tree Difference
50 9.406045 9.402718 +0.003328
100 9.409701 9.408041 +0.001660
200 9.411546 9.410717 +0.000829
400 9.412473 9.412059 +0.000414
Reading the output:
The scheme explodes when the ratio is above one. With ratios of 4, 2 and 1.33 the price is of the order of \(10^{64}\) to \(10^{93}\), and not a slightly wrong number. At a ratio of 1 and below the price is stable, and close to 9.41.
A stable price is not necessarily an accurate one, and more time steps do not help by themselves. The error is -0.0003 at 500 steps and -0.0021 at 4,000. It has a space part and a time part, and with the space grid fixed they do not simply add up. Refining both together, as in the next table, is what converges.
The error is second order in the space step. With the ratio fixed, halving \(\Delta x\) cuts the error by a factor of 4.0 to 4.3, at four times the number of time steps and so 16 times the work.
The explicit scheme and the trinomial tree are the same lattice. On the lattice of the tree, the explicit scheme and the trinomial tree give prices that differ by 0.0033 at 50 steps and by half as much each time the steps double, which is the effect of a different treatment of the discounting. PDE Methods, Part 3: American Options & Trees vs Finite Differences explains the link.
A valuation control view#
Check the stability condition in the code, and fail loudly: a scheme that is run with a ratio above the limit produces nonsense that can be mistaken for a price in a large batch. A check on the ratio, or an assertion that the price is within no-arbitrage bounds, is cheap.
Test the boundaries: move the ends of the grid outward and check that the price at the spot does not change. A price that depends on the boundary is partly the boundary.
Run a grid refinement test: the price at the spot grid and at a grid twice as fine, with the error rate (a factor of 4 for a second-order scheme). A ratio far from the expected one means the scheme is not in its asymptotic range, or that there is a bug.
Look for negative weights: \(p_m < 0\) is the signature of an unstable explicit scheme, and in an implicit scheme, of a loss of positivity that produces oscillations.
Record the grid and its range: they are part of the model specification, and different grids give different prices that are all within the numerical error. A change to the grid should be tested against the old one.
Next, PDE Methods, Part 2: Implicit & Crank-Nicolson removes the stability limit.