Transform Methods, Part 2: FFT & the COS Method#

The inversion integral of Transform Methods, Part 1: Characteristic Functions gives one price at a time, and a trader needs a whole strip of strikes, for a smile or a calibration. Two methods price all the strikes from one pass over the characteristic function: the fast Fourier transform of Carr and Madan, and the cosine expansion of Fang and Oosterlee. This is the second of two pages on transform methods.

The Carr-Madan method#

The call price as a function of the log strike \(k\) does not have a Fourier transform, because it tends to a constant as the strike falls to zero. Carr and Madan multiply it by a damping factor \(e^{\alpha k}\) with \(\alpha > 0\), which makes it decay, and take the transform of the damped price:

\[\psi(v) = \frac{e^{-rT} \, \varphi\left(v - (\alpha + 1)i\right)}{\alpha^2 + \alpha - v^2 + i(2\alpha + 1)v}, \qquad C(k) = \frac{e^{-\alpha k}}{\pi}\int_0^\infty e^{-ivk}\,\psi(v)\,dv\]

The integral is replaced by a sum over a grid of \(N\) points with spacing \(\eta\), and the sums for all \(N\) log strikes at once are a single fast Fourier transform, which takes \(N\log N\) operations. The strikes come out on a grid of spacing \(2\pi/(N\eta)\), and the price at a given strike is interpolated.

Two parameters matter. The damping \(\alpha\) must be small enough that the model has a moment of order \(\alpha + 1\), so that the function is defined, and large enough to give a good decay. The spacing \(\eta\) and the number of points trade the accuracy of the integral against the spacing of the strike grid.

The COS method#

The COS method expands the unknown density of the log price on an interval \([a, b]\) in cosines. The coefficients of the density come from the characteristic function, \(F_k = \tfrac{2}{b-a}\,\text{Re}\left[\varphi\left(\tfrac{k\pi}{b-a}\right) e^{-ik\pi a/(b-a)}\right]\), and the coefficients \(V_k\) of the payoff are known analytically. The price is a short sum:

\[C \approx e^{-rT}\sum_{k=0}^{N-1}{}' \; \text{Re}\left[ \varphi\left(\tfrac{k\pi}{b-a}\right) e^{-ik\pi a/(b-a)} \right] V_k\]

where the prime means that the first term is halved. For a density that is smooth, as it is for these models, the error of the cosine expansion falls exponentially in the number of terms \(N\), so a few dozen terms give machine accuracy. It prices each strike separately, but each takes only a sum, and the characteristic function is evaluated once for all strikes.

The truncation range \([a, b]\) must cover essentially all of the density. A common choice is the mean plus or minus 10 standard deviations of the log price. A range that is too narrow cuts off the tails and biases the price. A range that is too wide wastes terms. The range for a long maturity or a high volatility must be widened.

Worked example#

The example prices the benchmark call and a Heston call with the COS method for 8 to 256 terms, against the exact price and the Gil-Pelaez price. It then prices 15 Heston strikes from 70 to 140 by COS and by Carr-Madan, with two sizes of FFT, and times the three methods.

Python code
"""Carr-Madan FFT and the COS method, against Gil-Pelaez inversion, for Black-Scholes and Heston calls."""
import time

import numpy as np

from common import K, R, S0, SIGMA, T, bs_price
from fourier_cf_example import HESTON, cf_bs, cf_heston, gil_pelaez_call


def cos_call(cf, strikes, n_terms=128, half_width=10.0, spread=0.2, t=T):
    """COS method: expand the density of ln(S_T) in cosines on [a, b], with the coefficients from the characteristic function."""
    strikes = np.atleast_1d(strikes).astype(float)
    centre = np.log(S0) + R * t
    a, b = centre - half_width * spread * np.sqrt(t), centre + half_width * spread * np.sqrt(t)
    k = np.arange(n_terms)
    u = k * np.pi / (b - a)
    phi = cf(u) * np.exp(-1j * u * a)
    weights = np.ones(n_terms)
    weights[0] = 0.5
    out = []
    for strike in strikes:
        lo, hi = np.log(strike), b
        # Cosine coefficients of the payoff max(e^y - K, 0) on [log K, b].
        chi = (np.cos(u * (hi - a)) * np.exp(hi) - np.cos(u * (lo - a)) * np.exp(lo)
               + u * np.sin(u * (hi - a)) * np.exp(hi) - u * np.sin(u * (lo - a)) * np.exp(lo)) / (1 + u**2)
        psi = np.where(k == 0, hi - lo, (np.sin(u * (hi - a)) - np.sin(u * (lo - a))) / np.where(k == 0, 1, u))
        payoff_coeff = 2.0 / (b - a) * (chi - strike * psi)
        out.append(np.exp(-R * t) * np.sum(weights * np.real(phi) * payoff_coeff))
    return np.array(out)


def fft_call(cf, strikes, alpha=1.5, n=4096, eta=0.25, t=T):
    """Carr-Madan: one FFT gives the damped call price on a grid of log strikes, which is then interpolated."""
    lam = 2 * np.pi / (n * eta)
    v = eta * np.arange(n)
    b = n * lam / 2
    k_grid = -b + lam * np.arange(n)
    psi = np.exp(-R * t) * cf(v - (alpha + 1) * 1j) / (alpha**2 + alpha - v**2 + 1j * (2 * alpha + 1) * v)
    simpson = (3 + (-1) ** (np.arange(n) + 1) - (np.arange(n) == 0)) / 3
    x = np.exp(1j * b * v) * psi * eta * simpson
    calls = np.exp(-alpha * k_grid) / np.pi * np.fft.fft(x).real
    return np.interp(np.log(np.atleast_1d(strikes)), k_grid, calls)


if __name__ == "__main__":
    heston = lambda u: cf_heston(u, **HESTON)
    ref_bs = bs_price()
    ref_h = gil_pelaez_call(heston)
    print(f"Reference prices at strike {K:.0f}: Black-Scholes {ref_bs:.8f}, Heston (Gil-Pelaez) {ref_h:.8f}\n")

    print("COS method: error against the reference as the number of cosine terms rises")
    print(f"{'Terms':>6} {'Black-Scholes':>14} {'Heston':>12}")
    for n_terms in (8, 16, 32, 64, 128, 256):
        e_bs = cos_call(cf_bs, K, n_terms)[0] - ref_bs
        e_h = cos_call(heston, K, n_terms)[0] - ref_h
        print(f"{n_terms:>6} {e_bs:+14.2e} {e_h:+12.2e}")

    strikes = np.arange(70.0, 140.1, 5.0)
    print(f"\n{len(strikes)} strikes from {strikes[0]:.0f} to {strikes[-1]:.0f}: largest error of Heston calls against Gil-Pelaez")
    exact = np.array([gil_pelaez_call(heston, k) for k in strikes])
    cos = cos_call(heston, strikes, 128)
    fft = fft_call(heston, strikes)
    print(f"  COS, 128 terms:      {np.abs(cos - exact).max():.2e}")
    print(f"  Carr-Madan, 4096 points: {np.abs(fft - exact).max():.2e}")
    fft_coarse = fft_call(heston, strikes, n=256, eta=0.5)
    print(f"  Carr-Madan, 256 points:  {np.abs(fft_coarse - exact).max():.2e}")

    print("\nTime for all strikes (milliseconds)")
    for name, fn in (("Gil-Pelaez, one integral pair per strike", lambda: [gil_pelaez_call(heston, k) for k in strikes]),
                     ("COS, 128 terms", lambda: cos_call(heston, strikes, 128)),
                     ("Carr-Madan, 4096 points", lambda: fft_call(heston, strikes))):
        start = time.perf_counter()
        fn()
        print(f"  {name:<42} {(time.perf_counter() - start) * 1e3:8.1f}")

The output is:

Reference prices at strike 100: Black-Scholes 9.41340338, Heston (Gil-Pelaez) 9.24252107

COS method: error against the reference as the number of cosine terms rises
 Terms  Black-Scholes       Heston
     8      -1.74e+00    -2.40e+00
    16      -4.11e-02    -2.48e-01
    32      -8.45e-07    +3.10e-03
    64      +4.62e-14    +1.15e-06
   128      +4.62e-14    +1.25e-10
   256      +4.62e-14    +1.25e-10

15 strikes from 70 to 140: largest error of Heston calls against Gil-Pelaez
  COS, 128 terms:      5.02e-10
  Carr-Madan, 4096 points: 8.20e-04
  Carr-Madan, 256 points:  5.58e-02

Time for all strikes (milliseconds)
  Gil-Pelaez, one integral pair per strike      103.2
  COS, 128 terms                                  1.5
  Carr-Madan, 4096 points                         2.2
Absolute error of the COS price against the number of terms for Black-Scholes and Heston, on a logarithmic scale, falling steeply

Reading the output:

  • The COS error falls exponentially. For Black-Scholes it goes from 1.7 with 8 terms to 8e-07 with 32 terms and to machine precision with 64. Heston takes about twice as many: 3e-03 at 32, 1e-06 at 64 and 1e-10 at 128. A straight line on the logarithmic figure means exponential convergence, against the slow curves of the other methods.

  • After the limit, the error stops. The Heston error at 128 and at 256 is the same, 1.25e-10, which is probably the error of the reference integral, and not of the COS price. The check is limited by the reference.

  • COS is more accurate than the FFT for the same effort. With 128 terms the COS error over 15 strikes is 5e-10. The Carr-Madan result with 4,096 points is 8e-04, and with 256 points 6e-02, the error of the integral and of the interpolation in the strike. The FFT needs a fine grid.

  • Both are 50 to 70 times faster than inversion for 15 strikes. The time for the 15 prices is 103 ms for the inversion, 1.5 ms for COS and 2.2 ms for the FFT. The saving grows with the number of strikes, and it is the reason that calibration uses these methods (Calibration). Timings are indicative.

A valuation control view#

  • Check the truncation range of the COS method: widen it and see that the price does not change. A price that moves is truncated. The range for a one-week option and for a ten-year option is not the same.

  • Check the damping and the grid of the FFT: a different \(\alpha\) or \(\eta\) should give the same price within tolerance. A price that depends on \(\alpha\) is not converged, or the model does not have the moment that \(\alpha\) needs.

  • Test deep in and out of the money: the relative accuracy of a very small price is poor with the FFT, since the absolute error is roughly constant. It matters for far out-of-the-money options, which are the ones that drive tail risk.

  • Compare against inversion, not only against itself: the slower method with one integral per strike is an independent check of the faster ones.

  • Use these methods for calibration with care: the price is exact enough for the optimiser, but the calibration is another matter, because the parameters of the model are not all identified by the prices. See Calibration.

Next, Numerical Methods: Supporting Methods covers the tools that these methods and every other pricing engine rest on, starting with linear algebra and ending with the numerical integration behind the inversion integral.