Module contents
Stage 4 of 8Advanced 100 min

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

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: F=100F=100, zero rates and dividends, θ=0.04T\theta=0.04T, φ(θ)=2/(1+θ)\varphi(\theta)=2/(1+\theta), and adjustable skew. The sufficient conditions seen earlier hold for all θ>0\theta>0 when ∣ρ∣≤0.8|\rho|\le0.8: θφ<2\theta\varphi<2 and θφ2≤1\theta\varphi^2\le1, so multiplying by 1+∣ρ∣1+|\rho| keeps them below 4.

InteractiveFrom implied to local volatility
  • Implied
  • Local
Scene: x = 4k, y = (T − 0.55)/0.225, height = 5 × volatility.
Slice for T = 0.1
−0.50
ATM implied slope−0.0996
ATM local slope−0.1995
Rotate the surfaces and change ρ. The blue surface is implied and the red mesh is local; the slice compares both at T = 0.1. Scene coordinates are shown in the figure. Near the money, compare the live slopes; the approximate ratio of two applies to this family at short maturities.

Derivation from the forward equation

Suppose a positive underlying has risk-neutral dynamics

 ⁣dSt=(r−q)St ⁣dt+σloc(St,t)St ⁣dWt,\dd S_t=(r-q)S_t\dd t+\sigma_{\mathrm{loc}}(S_t,t)S_t\dd W_t,

with constant deterministic r,qr,q, 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 p(s,T)p(s,T) is

∂Tp=−∂s((r−q)sp)+12∂ss(σloc2(s,T)s2p).\partial_Tp=-\partial_s\big((r-q)sp\big)+\tfrac12\partial_{ss}\big(\sigma_{\mathrm{loc}}^2(s,T)s^2p\big).

The call price is C(K,T)=e−rT∫K∞(s−K)p(s,T) ⁣dsC(K,T)=e^{-rT}\int_K^\infty(s-K)p(s,T)\dd s. Differentiate in TT, substitute the equation, integrate the drift term by parts once and the diffusion term twice. At the lower boundary (s−K)(s-K) is zero; the second diffusion integration leaves the term at s=Ks=K. Using CK=−e−rT∫K∞p ⁣dsC_K=-e^{-rT}\int_K^\infty p\dd s and CKK=e−rTp(K,T)C_{KK}=e^{-rT}p(K,T) gives

∂TC=12σloc2(K,T)K2CKK−(r−q)KCK−qC.\partial_TC=\tfrac12\sigma_{\mathrm{loc}}^2(K,T)K^2C_{KK}-(r-q)KC_K-qC.

Therefore, where CKK>0C_{KK}>0,

σloc2(K,T)=∂TC+(r−q)K∂KC+qC12K2∂KKC.\sigma_{\mathrm{loc}}^2(K,T)= \frac{\partial_TC+(r-q)K\partial_KC+qC}{\tfrac12K^2\partial_{KK}C}.

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 k=log⁡(K/FT)k=\log(K/F_T), FT=S0e(r−q)TF_T=S_0e^{(r-q)T}, and w(k,T)=Tσimp2(k,T)w(k,T)=T\sigma_{\rm imp}^2(k,T). Substituting Black into the preceding equation and applying the chain rule, including the dependence of kk on TT at fixed KK, gives Gatheral’s form

σloc2(k,T)=∂Tw(k,T)g(k,T),g=(1−kwk2w)2−wk24(1w+14)+wkk2.\sigma_{\mathrm{loc}}^2(k,T)=\frac{\partial_Tw(k,T)}{g(k,T)},\quad g=\left(1-\frac{k w_k}{2w}\right)^2-\frac{w_k^2}{4}\left(\frac1w+\frac14\right)+\frac{w_{kk}}2.

Here ∂Tw\partial_Tw is taken at fixed kk, not fixed strike. The numerator is normalized calendar slope and gg is the butterfly function from the second lesson. The formula alone does not guarantee a well-behaved diffusion: it requires w>0w>0, g>0g>0, a nonnegative numerator, and regularity and boundary conditions. A finite grid discovers problems only where evaluated.

For the figure’s family, define θ=0.04T\theta=0.04T, ϕ=2/(1+θ)\phi=2/(1+\theta), z=ϕkz=\phi k, and R=(z+ρ)2+1−ρ2R=\sqrt{(z+\rho)^2+1-\rho^2}. The derivatives used in the calculation are

wk=θϕ2(ρ+z+ρR),wkk=θϕ2(1−ρ2)2R3,wT=0.04[1+ρz+R2+θkϕ′2(ρ+z+ρR)],ϕ′=−2(1+θ)2.\begin{aligned} w_k&=\frac{\theta\phi}{2}\left(\rho+\frac{z+\rho}{R}\right),\\ w_{kk}&=\frac{\theta\phi^2(1-\rho^2)}{2R^3},\\ w_T&=0.04\left[\frac{1+\rho z+R}{2}+\frac{\theta k\phi'}2\left(\rho+\frac{z+\rho}{R}\right)\right], \quad \phi'=-\frac{2}{(1+\theta)^2}. \end{aligned}

The derivatives are analytical: differentiating noisy IV twice directly would amplify errors. At T=0T=0 the expressions above divide by w=0w=0; for the first step we use this family’s ATM limit, 0.20.2, and check step sensitivity. In the figure, at T=0.1T=0.1 and ρ=−0.5\rho=-0.5, 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 Xt=log⁡(St/S0)X_t=\log(S_t/S_0), Itô gives  ⁣dXt=−σloc2(Xt,t) ⁣dt/2+σloc(Xt,t) ⁣dWt\dd X_t=-\sigma_{\rm loc}^2(X_t,t)\dd t/2+\sigma_{\rm loc}(X_t,t)\dd W_t. The local-volatility Monte Carlo scheme uses Euler in log-price, keeping St>0S_t>0. 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 ρ=−0.5\rho=-0.5, not the previous lesson’s historical parameters. It is chosen because it has an explicit smooth extension to T=0T=0 and sufficient conditions verifiable across the domain. S0=F=100S_0=F=100, 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.

[ ]Surface and analytical derivativesLocal GPU
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.)
This cell needs the local lab (PyTorch with your GPU). Start it with 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.

[ ]One million paths and repricingLocal GPU
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))
This cell needs the local lab (PyTorch with your GPU). Start it with npm run lab and open the connection link.

In the RTX 3060 run with seed 13, the 14 points between K=85K=85 and 115115 at T=0.5T=0.5 and 11 had maximum absolute error 0.000753, below 0.002, or 0.2 volatility percentage points. At K=85,T=1K=85,T=1, 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.

[ ]Paired step-size comparisonLocal GPU
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))
This cell needs the local lab (PyTorch with your GPU). Start it with 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 F=K=100F=K=100, T=1T=1, σ=0.2\sigma=0.2, and discount one. If Y=(ST−K)+Y=(S_T-K)^+, truncated lognormal moments give its variance, and vega converts a small price change into an IV change.

[ ]Payoff standard deviation and Black vegaBrowser
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)))
ProofFrom Fokker-Planck to Dupire
Prove: Derive Dupire's price equation from the forward density under the assumptions and boundary conditions in the text.
0
C(K,T) = exp(−rT) ∫_K^∞ (s−K)p(s,T) ds.

Step 1 of 3. What does the second derivative in K identify?

NumericMonte Carlo budget
A one-year ATM call has payoff standard deviation 13.15307 and vega 39.69525 per unit of volatility. With independent paths, estimate the minimum integer N for approximate IV standard error at most 0.001 (0.1 volatility points).
QuizUnstable ratio
A fitted smile has negative g over a region while ∂T w is positive. What does that mean for Dupire in that region?
CodeDupire with surface derivatives
Implement local_vol(k,T,surface). surface(k,T) returns (w, wt, wk, wkk), with wt taken at fixed k. Accept NumPy scalars or arrays and reject w ≤ 0, wt < 0, or g ≤ 0. Return the square root of wt/g.
def local_vol(k,T,surface):
  raise NotImplementedError()
Shift+Enter to run

Ideas to remember

Key idea
Dupire transforms the time slope of total variance and price curvature into a local diffusion; stability depends on both, and matching vanillas does not identify the entire dynamics.

Discretization and Monte Carlo error require different checks. An arbitrageable or noisy surface can break the formula before any simulation begins.