Calibration#
A model has parameters that are not quoted: the volatility of volatility, the speed of mean reversion, the correlation of a stock with its variance. They are found by calibration, which chooses the parameters that make the model reproduce the prices of liquid instruments. Calibration is an optimisation problem (Optimisation), and it often rests on regression and curve fitting (Numerical Methods: Regression and Fitting) and on root finding (Root Finding: Implied Volatility) to turn prices into volatilities. Numerical choices in it, such as the starting point and the weights, can change the parameters, and with them the prices of the products that the model is used for. This page sets out the problem, and shows what a calibration can and cannot determine.
Calibration as least squares#
Given market prices \(C_i^{mkt}\) for \(n\) options and a model with parameters \(\theta\), solve
subject to bounds on the parameters, such as a variance that is positive and a correlation between -1 and 1. The weights \(w_i\) say how much each option matters. Using a weight of one over the vega makes the price error close to an error in implied volatility, which is how a market quotes. Without weights the optimiser fits the expensive options, such as long-dated ones, and neglects the cheap ones.
Choosing the optimiser#
The methods are set out in Optimisation. For calibration, two points matter.
Gradient-based and least-squares methods (Levenberg-Marquardt, trust region) are fast, and find the nearest minimum, which may not be the best. A global method, such as differential evolution, is slower and less precise, and is used to find a starting point.
The objective needs a fast pricer. One calibration calls the pricer thousands of times, and so a closed form or a transform method (Transform Methods, Part 2: FFT & the COS Method) is used, and not a simulation, which is slow and noisy.
What can go wrong#
Local minima. The error surface has more than one valley. The optimiser reports the one that it falls into, and a different start gives a different answer.
Flat directions. Different combinations of parameters give almost the same prices. The optimiser is then free to move along the valley, and the parameters found are not determined by the data, even when the fit is excellent. The cause is identifiability: the market data say little about some parameters.
Noise. Market prices carry a bid-offer and a rounding. The parameters respond to the noise, and strongly when they are weakly identified.
Instability over time. The daily parameters jump when a flat direction is resolved differently from one day to the next, though the prices are stable.
The practical symptom is a good fit with parameters that are unstable. The test is to look at the prices of instruments that were not in the calibration set.
Risk through the calibration#
The parameters are a function of the quotes, \(\theta(q)\), so the risk of a product to a quote is the chain rule: the sensitivity of the price to the parameters times the sensitivity of the parameters to the quote. The second factor is the Jacobian of the calibration. For a least-squares fit with small residuals it is \((J^\top J)^{-1} J^\top\), with \(J\) the matrix of derivatives of the model prices with respect to the parameters, and it gives the risk to every quote from one linear solve. The alternative is to bump each quote and recalibrate, which costs a calibration per quote and depends on the tolerance of the optimiser. The derivation and a worked example are in The Jacobian.
Worked example#
The example generates 20 Heston call prices from known parameters (four maturities and five strikes), and calibrates the model to them, using the COS pricer of Transform Methods, Part 2: FFT & the COS Method and vega weights. First it starts from four different points, with exact prices. Then it adds noise of about 0.2 volatility points, repeats the calibration 12 times, and measures the spread of the parameters. Finally it uses the 1-year options only, as if only one maturity were quoted. It compares a quoted price and a product outside the calibration set, a five-year call at 130% of the forward.
Python code
"""Calibration as optimisation: fit the Heston model to a set of option prices, from different starts and with noisy quotes."""
import numpy as np
from scipy.optimize import least_squares
from common import R, S0, bs_greeks, bs_price
from fourier_cf_example import cf_heston
from fourier_fft_cos_example import cos_call
NAMES = ["v0", "kappa", "theta", "xi", "rho"]
TRUE = np.array([0.05, 1.5, 0.06, 0.50, -0.65])
LOWER = np.array([0.001, 0.05, 0.001, 0.05, -0.99])
UPPER = np.array([0.50, 10.0, 0.50, 2.00, 0.99])
EXPIRIES = (0.25, 0.5, 1.0, 2.0)
MONEYNESS = (0.8, 0.9, 1.0, 1.1, 1.2)
GRID = [(t, m * S0 * np.exp(R * t)) for t in EXPIRIES for m in MONEYNESS]
def heston_prices(params, grid=GRID, terms=96):
v0, kappa, theta, xi, rho = params
out = []
for t in sorted({g[0] for g in grid}):
strikes = [k for tt, k in grid if tt == t]
out.extend(cos_call(lambda u: cf_heston(u, t=t, v0=v0, kappa=kappa, theta=theta, xi=xi, rho=rho),
strikes, terms, spread=0.35, t=t))
return np.array(out)
def implied_vol(price, strike, t):
from scipy.optimize import brentq
return brentq(lambda s: bs_price(S0, strike, R, s, t) - price, 1e-4, 3.0)
def calibrate(market, start, weights, grid=GRID):
"""Least squares on vega-weighted price differences, which are close to differences in implied volatility."""
return least_squares(lambda p: (heston_prices(p, grid) - market) * weights, start, bounds=(LOWER, UPPER), xtol=1e-10, ftol=1e-10)
def vol_rmse(params, market, grid=GRID):
model = heston_prices(params, grid)
errs = [implied_vol(m, k, t) - implied_vol(p, k, t) for m, p, (t, k) in zip(market, model, grid)]
return np.sqrt(np.mean(np.square(errs))) * 100
if __name__ == "__main__":
market = heston_prices(TRUE)
vegas = np.array([bs_greeks(S0, k, R, implied_vol(p, k, t), t)[2] for p, (t, k) in zip(market, GRID)])
weights = 1.0 / vegas
print(f"{len(GRID)} option prices generated from: " + ", ".join(f"{n} {v}" for n, v in zip(NAMES, TRUE)))
print(f"Implied volatilities, 1 year: " + " ".join(f"{implied_vol(p, k, t):.3f}" for p, (t, k) in zip(market, GRID) if t == 1.0) + "\n")
print("Fits to the exact prices from four starting points")
print(f"{'Start':<24} " + " ".join(f"{n:>7}" for n in NAMES) + f" {'RMSE vol pts':>13} {'evaluations':>12}")
starts = {"Near the truth": [0.04, 1.0, 0.05, 0.4, -0.5], "Flat smile": [0.04, 2.0, 0.04, 0.1, 0.0],
"High vol of vol": [0.10, 5.0, 0.10, 1.5, 0.5], "Low mean reversion": [0.02, 0.1, 0.02, 0.3, -0.9]}
for name, start in starts.items():
res = calibrate(market, np.array(start), weights)
print(f"{name:<24} " + " ".join(f"{v:7.4f}" for v in res.x) + f" {vol_rmse(res.x, market):13.5f} {res.nfev:12d}")
# Noisy quotes: each price is moved by a random amount worth about 0.2 volatility points.
rng = np.random.default_rng(21)
runs = 12
fitted, rmses = [], []
for _ in range(runs):
noisy = market + rng.standard_normal(len(market)) * 0.002 * vegas
res = calibrate(noisy, np.array(starts["Near the truth"]), weights)
fitted.append(res.x)
rmses.append(vol_rmse(res.x, noisy))
fitted = np.array(fitted)
print(f"\n{runs} noisy sets of quotes (0.2 volatility points of noise), fitted from the same start")
print(f"{'':<12} " + " ".join(f"{n:>8}" for n in NAMES))
print(f"{'Mean':<12} " + " ".join(f"{v:8.4f}" for v in fitted.mean(axis=0)))
print(f"{'Std dev':<12} " + " ".join(f"{v:8.4f}" for v in fitted.std(axis=0, ddof=1)))
print(f"{'True':<12} " + " ".join(f"{v:8.4f}" for v in TRUE))
print(f"{'Spread / true':<12} " + " ".join(f"{abs(v):8.1%}" for v in fitted.std(axis=0, ddof=1) / np.abs(TRUE)))
print(f"Fit error in each run: {np.mean(rmses):.3f} volatility points on average")
# The quotes are fitted within the noise whatever the parameters. A product outside the quoted set depends on them more.
inside = np.array([heston_prices(p, [(1.0, S0 * np.exp(R))])[0] for p in fitted])
outside = np.array([heston_prices(p, [(5.0, 1.3 * S0 * np.exp(5 * R))], terms=256)[0] for p in fitted])
true_in = heston_prices(TRUE, [(1.0, S0 * np.exp(R))])[0]
true_out = heston_prices(TRUE, [(5.0, 1.3 * S0 * np.exp(5 * R))], terms=256)[0]
print(f"\n1 year at the money (quoted): true {true_in:.4f}, fitted mean {inside.mean():.4f}, std dev {inside.std(ddof=1):.4f} ({inside.std(ddof=1) / true_in:.2%})")
print(f"5 year, strike 130% (not quoted): true {true_out:.4f}, fitted mean {outside.mean():.4f}, std dev {outside.std(ddof=1):.4f} ({outside.std(ddof=1) / true_out:.2%})")
# Only one expiry quoted: five prices for five parameters. The smile of that expiry is matched, and the term structure is not.
one = [g for g in GRID if g[0] == 1.0]
market_one = heston_prices(TRUE, one)
weights_one = weights[[i for i, g in enumerate(GRID) if g[0] == 1.0]]
fitted_one, rmse_one = [], []
for _ in range(runs):
noisy = market_one + rng.standard_normal(len(one)) * 0.002 * vegas[[i for i, g in enumerate(GRID) if g[0] == 1.0]]
res = calibrate(noisy, np.array(starts["Near the truth"]), weights_one, one)
fitted_one.append(res.x)
rmse_one.append(vol_rmse(res.x, noisy, one))
fitted_one = np.array(fitted_one)
print(f"\n{runs} noisy sets with only the 1 year expiry quoted")
print(f"{'':<12} " + " ".join(f"{n:>8}" for n in NAMES))
print(f"{'Mean':<12} " + " ".join(f"{v:8.4f}" for v in fitted_one.mean(axis=0)))
print(f"{'Std dev':<12} " + " ".join(f"{v:8.4f}" for v in fitted_one.std(axis=0, ddof=1)))
print(f"{'Spread / true':<12} " + " ".join(f"{abs(v):8.1%}" for v in fitted_one.std(axis=0, ddof=1) / np.abs(TRUE)))
print(f"Fit error in each run: {np.mean(rmse_one):.3f} volatility points on average")
in_one = np.array([heston_prices(p, [(1.0, S0 * np.exp(R))])[0] for p in fitted_one])
out_one = np.array([heston_prices(p, [(5.0, 1.3 * S0 * np.exp(5 * R))], terms=256)[0] for p in fitted_one])
print(f"1 year at the money (quoted): fitted mean {in_one.mean():.4f}, std dev {in_one.std(ddof=1):.4f} ({in_one.std(ddof=1) / true_in:.2%})")
print(f"5 year, strike 130% (not quoted): fitted mean {out_one.mean():.4f}, std dev {out_one.std(ddof=1):.4f} ({out_one.std(ddof=1) / true_out:.2%})")
The output is:
20 option prices generated from: v0 0.05, kappa 1.5, theta 0.06, xi 0.5, rho -0.65
Implied volatilities, 1 year: 0.259 0.235 0.213 0.194 0.181
Fits to the exact prices from four starting points
Start v0 kappa theta xi rho RMSE vol pts evaluations
Near the truth 0.0500 1.5000 0.0600 0.5000 -0.6500 0.00000 6
Flat smile 0.0500 1.5000 0.0600 0.5000 -0.6500 0.00000 10
High vol of vol 0.0500 1.5000 0.0600 0.5000 -0.6500 0.00000 10
Low mean reversion 0.0500 1.5000 0.0600 0.5000 -0.6500 0.00000 10
12 noisy sets of quotes (0.2 volatility points of noise), fitted from the same start
v0 kappa theta xi rho
Mean 0.0499 1.4663 0.0603 0.4992 -0.6479
Std dev 0.0005 0.1360 0.0017 0.0241 0.0121
True 0.0500 1.5000 0.0600 0.5000 -0.6500
Spread / true 1.0% 9.1% 2.9% 4.8% 1.9%
Fit error in each run: 0.158 volatility points on average
1 year at the money (quoted): true 8.4702, fitted mean 8.4594, std dev 0.0227 (0.27%)
5 year, strike 130% (not quoted): true 9.0573, fitted mean 9.0376, std dev 0.0983 (1.08%)
12 noisy sets with only the 1 year expiry quoted
v0 kappa theta xi rho
Mean 0.1843 4.9330 0.1078 1.1282 -0.6279
Std dev 0.1269 3.9042 0.1732 0.6788 0.0567
Spread / true 253.7% 260.3% 288.6% 135.8% 8.7%
Fit error in each run: 0.068 volatility points on average
1 year at the money (quoted): fitted mean 8.4457, std dev 0.0457 (0.54%)
5 year, strike 130% (not quoted): fitted mean 6.7961, std dev 6.4978 (71.74%)
Reading the output:
With a full set of quotes, the calibration is well behaved. From four different starting points, including a flat smile and a high volatility of volatility, it finds the true parameters, with 6 to 10 evaluations of the objective, not counting those of the numerical Jacobian, and an error of zero. The error surface is a single valley here.
Noise moves the parameters, and some more than others. With 0.2 volatility points of noise, the long-run variance \(\theta\) is stable to 2.9%, but the mean reversion \(\kappa\) varies by 9.1%, the largest relative spread. The prices of the quoted options hardly move, 0.27% at one year.
With one expiry, the parameters are not determined. Five prices are fitted almost perfectly, 0.07 volatility points on average, and yet \(\kappa\) ranges over 4.9 \(\pm\) 3.9, \(v_0\) is 0.18 \(\pm\) 0.13 against a true 0.05, and the spread of each is over 100% of the true value except for the correlation.
The product outside the set pays for it. The one-year option, which was quoted, varies by 0.54%. The five-year option, which was not, has a standard deviation of 6.5 on a price of 9.06, 72%. With the full set of quotes the same option varies by 1.1%. The fit to the quotes tells nothing about this.
A valuation control view#
Look at the stability of the parameters, not only the fit: the day-to-day movement, and the spread of the result from different starting points and from small changes in the quotes. A calibration that fits well and moves a lot is under-identified.
Test on instruments that were not fitted: a product outside the calibration set is the real test. The out-of-sample price error here is 72% where the in-sample fit error is 0.07 volatility points.
Record the settings: the instruments, the weights, the bounds, the starting point and the tolerance. They are part of the model, and a change in any of them changes the parameters. See Model Risk in Valuation.
Treat the non-identified parameters as model risk: where the data cannot determine a parameter, its range is an uncertainty, and the effect on the products that depend on it is the basis of a reserve. For mean reversion in rates this is the subject of Interest Rate Mean Reversion, Part 4: Risk & Reserves.
Use a fast, accurate pricer inside the loop: a simulation with noise in its price makes the objective rough, the optimiser stops early, and the parameters differ between runs for reasons that have nothing to do with the market.
Next, Numerical Methods: Advanced Methods covers early exercise by simulation, which uses regression inside a Monte Carlo, and what happens as the number of factors grows.