Dupire local volatility and Monte Carlo
Derive Dupire's formula in implied total variance, calculate local volatility from the SSVI surface, and simulate the model by Monte Carlo to check vanilla repricing. Examine why an arbitrage-free input surface is essential and how discretization error propagates.
After this lesson you can
- Derive Dupire's formula from the Fokker-Planck equation.
- Calculate local volatility stably from a total-variance surface.
- Simulate the local-volatility diffusion using Euler in log-price.
- Verify vanilla repricing within Monte Carlo error.
Before you start
- P03SSVI surfaceArbitrage-free calibrationRisk-neutral density
- 26Stochastic differential equationItô's lemmaEuler-Maruyama schemeFokker-Planck equationStrong and weak convergence
- 09Monte Carlo error and confidence intervals
- 29Bias-variance-cost tradeoff in simulation
- 28Dupire local volatilityHeston modelSABR model
From today’s prices to dynamics
A European option surface describes risk-neutral marginal distributions for each maturity. It does not by itself determine how the asset moves between dates. Dupire local volatility chooses a diffusion whose instantaneous intensity depends on level and time and, under regularity assumptions, reproduces those marginals. It can therefore reproduce vanillas while differing from other models for path-dependent products.
The SSVI surface provides a smooth, constrained input. The figure uses one particular family rather than market data: , zero rates and dividends, , , and adjustable skew. The sufficient conditions seen earlier hold for all when : and , so multiplying by keeps them below 4.
Derivation from the forward equation
Suppose a positive underlying has risk-neutral dynamics
with constant deterministic , a sufficiently regular density, and boundary terms vanishing under integration by parts. To simplify the derivation, assume non-explosive diffusion and finite required moments. The Fokker-Planck equation for density is
The call price is . Differentiate in , substitute the equation, integrate the drift term by parts once and the diffusion term twice. At the lower boundary is zero; the second diffusion integration leaves the term at . Using and gives
Therefore, where ,
The Breeden-Litzenberger identity explains the denominator: it is proportional to density. If density is very small, a small data perturbation can be amplified. Negative density cannot describe a real diffusion with that distribution; at zero, division is singular. A surface decreasing in calendar time can give a negative numerator. Silently clipping the ratio to zero would hide the input problem.
The total-variance form
Write , , and . Substituting Black into the preceding equation and applying the chain rule, including the dependence of on at fixed , gives Gatheral’s form
Here is taken at fixed , not fixed strike. The numerator is normalized calendar slope and is the butterfly function from the second lesson. The formula alone does not guarantee a well-behaved diffusion: it requires , , a nonnegative numerator, and regularity and boundary conditions. A finite grid discovers problems only where evaluated.
For the figure’s family, define , , , and . The derivatives used in the calculation are
The derivatives are analytical: differentiating noisy IV twice directly would amplify errors. At the expressions above divide by ; for the first step we use this family’s ATM limit, , and check step sensitivity. In the figure, at and , ATM slopes are approximately −0.0996 implied and −0.1995 local. The ratio near two is a short-maturity property of this example, not a universal identity for every surface and maturity.
Simulate and reprice
With zero rates and , Itô gives . The local-volatility Monte Carlo scheme uses Euler in log-price, keeping . Error has two components: sampling error decreases with path count, while time discretization error does not disappear by increasing that count alone. Paired paths with the same Brownian increments measure the step effect more precisely.
The lab reproduces exactly the figure’s family with , not the previous lesson’s historical parameters. It is chosen because it has an explicit smooth extension to and sufficient conditions verifiable across the domain. , without discounting. It runs one million paths, 256 steps, and seven strikes at each of two maturities. A fixed seed permits repetition, though CPU and GPU do not necessarily generate the same sequence.
import math
import numpy as np
import torch
from scipy.special import ndtr
from scipy.optimize import brentq
def ssvi(k,T,eta=2.,rho=-.5,v=.2):
theta=v*v*T; phi=eta/(1+theta); z=phi*k
R=np.sqrt((z+rho)**2+1-rho*rho)
return theta/2*(1+rho*z+R)
def local_vol(k,T,eta=2.,rho=-.5,v=.2):
# k es un tensor de PyTorch, T > 0 y el forward es constante.
if T<=0: raise ValueError('Usa el límite inicial en T=0')
theta=v*v*T; phi=eta/(1+theta); dphi=-eta/(1+theta)**2
z=phi*k; R=torch.sqrt((z+rho)**2+1-rho*rho); q=rho+(z+rho)/R
w=theta/2*(1+rho*z+R); wk=theta*phi*q/2
wkk=theta*phi**2*(1-rho*rho)/(2*R**3)
wt=v*v*((1+rho*z+R)/2+theta*q*k*dphi/2)
g=(1-k*wk/(2*w))**2-wk**2*(1/w+.25)/4+wkk/2
return torch.sqrt(wt/g)
def black(K,T,sigma):
z=np.log(100/K)/(sigma*np.sqrt(T))+sigma*np.sqrt(T)/2
return 100*ndtr(z)-K*ndtr(z-sigma*np.sqrt(T))
def implied(price,K,T):
return brentq(lambda sigma:black(K,T,sigma)-price,.001,4.)npm run lab and open the connection link.The ratio is evaluated directly without replacing negative values by zero: an invalid input should fail visibly. The next test reports deviation in volatility units and approximates IV standard error by price standard error divided by input Black vega. The approximation is local; in low-vega wings it is safer to invert both endpoints of a price interval.
device='cuda' if torch.cuda.is_available() else 'cpu'
n=1_000_000; steps=256; dt=1/steps; rng=torch.Generator(device=device).manual_seed(13)
x=torch.zeros(n,device=device); strikes=np.array([85.,90.,95.,100.,105.,110.,115.]); errors=[]
print('dispositivo',torch.cuda.get_device_name() if device=='cuda' else 'CPU','trayectorias',n,'pasos',steps)
for i in range(steps):
t=i*dt
sigma=local_vol(x,t) if i else torch.full_like(x,.2)
x=x-sigma*sigma*dt/2+sigma*math.sqrt(dt)*torch.randn(n,device=device,generator=rng)
if i+1 in (steps//2,steps):
if not torch.isfinite(x).all(): raise ValueError('Trayectorias no finitas')
T=(i+1)*dt; S=100*torch.exp(x)
for K in strikes:
payoff=(S-K).clamp_min(0); price=payoff.mean().item()
se=(payoff.std(unbiased=True)/math.sqrt(n)).item()
target=np.sqrt(ssvi(np.log(K/100),T)/T); iv=implied(price,K,T)
d1=np.log(100/K)/(target*np.sqrt(T))+target*np.sqrt(T)/2
vega=100*np.exp(-d1*d1/2)/np.sqrt(2*np.pi)*np.sqrt(T)
errors.append(abs(iv-target))
print('T',T,'K',K,'IV revalorada',iv,'IV entrada',target,'error',iv-target,'SE IV aprox',se/vega)
print('máximo error absoluto de IV',max(errors))npm run lab and open the connection link.In the RTX 3060 run with seed 13, the 14 points between and at and had maximum absolute error 0.000753, below 0.002, or 0.2 volatility percentage points. At , the difference was −0.000753 and approximate standard error 0.000593. These figures belong to this run and synthetic grid; they are neither a simultaneous guarantee nor a result on real quotes. The range is called a test range here, without claiming liquidity in a particular market.
To isolate step-size effects, generate the four fine increments composing each coarse step and use them in both paths. Payoff difference is paired: its standard error is calculated on differences, not by adding uncertainties from two independent simulations.
rng=torch.Generator(device=device).manual_seed(21)
fine=torch.zeros(n,device=device); coarse=torch.zeros_like(fine); accumulated=torch.zeros_like(fine)
for i in range(steps):
t=i*dt; z=torch.randn(n,device=device,generator=rng); accumulated+=z
sigma=local_vol(fine,t) if i else torch.full_like(fine,.2)
fine+=-sigma*sigma*dt/2+sigma*math.sqrt(dt)*z
if (i+1)%4==0:
t0=(i-3)*dt; sigma=local_vol(coarse,t0) if i>=4 else torch.full_like(coarse,.2)
coarse+=-sigma*sigma*(4*dt)/2+sigma*math.sqrt(dt)*accumulated
accumulated.zero_()
if not torch.isfinite(fine).all() or not torch.isfinite(coarse).all(): raise ValueError('Trayectorias no finitas')
for K in (85.,100.,115.):
diff=(100*torch.exp(fine)-K).clamp_min(0)-(100*torch.exp(coarse)-K).clamp_min(0)
print('K',K,'precio fino menos grueso',diff.mean().item(),'SE pareado',diff.std(unbiased=True).item()/math.sqrt(n))npm run lab and open the connection link.With seed 21, price differences for 256 minus 64 steps were 0.00392, −0.00219, and −0.00583 for the three strikes. Corresponding paired standard errors were 0.000246, 0.000182, and 0.000111. There is a detectable step difference in this experiment: repricing near the input does not prove temporal bias is exactly zero. An additional comparison with more steps helps study convergence; the differences are not a confidence interval for the continuous limit.
The vanilla repricing check compares simulation prices or IV against the generating surface. It separates market-fit error, simulation error, and numerical inversion error. The first is absent here because the input is synthetic; the second is estimated from payoffs and the third depends especially on vega. Matching vanillas does not certify barrier prices or future volatility, which depend on joint dynamics.
Exercises
For the budget exercise, these figures come from a Black call with , , , and discount one. If , truncated lognormal moments give its variance, and vega converts a small price change into an IV change.
import numpy as np
from scipy.special import ndtr
s=.2; F=K=100.
p=ndtr(-s/2); e1=F*ndtr(s/2); e2=F**2*np.exp(s*s)*ndtr(1.5*s)
mean=e1-K*p; sd=np.sqrt(e2-2*K*e1+K*K*p-mean*mean)
vega=F*np.exp(-s*s/8)/np.sqrt(2*np.pi)
print('desviación del pago',sd,'vega',vega,'N mínimo',int(np.ceil((sd/(.001*vega))**2)))Step 1 of 3. What does the second derivative in K identify?
def local_vol(k,T,surface):
raise NotImplementedError()Ideas to remember
Discretization and Monte Carlo error require different checks. An arbitrageable or noisy surface can break the formula before any simulation begins.