Module contents
Lesson 16 of 30Advanced 120 min

Stochastic volatility, jumps and calibration

Study Heston, jump-diffusion and SABR models, Fourier pricing, simulation, calibration and smile dynamics.

After this lesson you can

  • Write Heston's model, derive its characteristic function and explain Feller's condition and parameter effects.
  • Price European options using COS and Carr-Madan while controlling truncation and term count.
  • Simulate Heston with Andersen's nonnegative-variance QE scheme and compare truncated Euler.
  • Calibrate Heston and Merton to a noisy surface and diagnose weakly identified parameters.
  • Apply the SABR asymptotic formula and compare local and stochastic-volatility smile dynamics.

Before you start

One surface, several dynamics

Local volatility can reproduce today’s European prices under Dupire’s assumptions, but those prices do not identify the underlying’s temporal dependence. Pricing path-dependent derivatives or estimating hedges requires additional dynamics. An observed smile does not by itself prove the following model true.

In the Heston model, under a risk-neutral measure and zero dividend,

dStSt=r dt+vt dWtS,dvt=κ(θ−vt)dt+ξvt dWtv,d⟨WS,Wv⟩t=ρ dt.\frac{dS_t}{S_t}=r\,dt+\sqrt{v_t}\,dW^S_t,\qquad dv_t=\kappa(\theta-v_t)dt+\xi\sqrt{v_t}\,dW^v_t,\qquad d\langle W^S,W^v\rangle_t=\rho\,dt.

v0v_0 determines the instantaneous level; θ\theta is the long-run mean and κ\kappa the mean-reversion speed. ξ\xi is volatility of variance. Negative correlation often tilts the smile: price falls accompanied by variance increases represent a mechanism consistent with the leverage effect. Curvature and maturities depend on several parameters at once.

The Feller condition 2κθ≥ξ22\kappa\theta\ge\xi^2 makes zero unattainable for a CIR variance started positive under usual assumptions. If it fails, zero may be reached but the continuous solution remains nonnegative. Naive Euler can produce negative variances: a numerical correction must state its bias.

InteractiveHeston controls
  • T = 0.25
  • T = 1
  • T = 2
0.04
0.04
1.5
0.50
-0.7
2κθ − ξ²-0.130
Omitted points0
The Feller condition fails, so zero may be attainable.
Smiles calculated with COS and synthetic prices for S = 100, r = 3%, three maturities and strikes 70 to 130. Change Heston parameters; the warning shows whether Feller fails. Implied-volatility inversion uses an approximate normal CDF.

Characteristic function and Fourier

For XT=log⁡STX_T=\log S_T, the affine property lets us write ϕ(u)=EQ[eiuXT]=exp⁡(C(T,u)+D(T,u)v0+iulog⁡S0)\phi(u)=E_Q[e^{iuX_T}]=\exp(C(T,u)+D(T,u)v_0+iu\log S_0). Substituting this form into the pricing equation converts the PDE into Riccati equations for C,DC,D.

In time to maturity, with C(0,u)=D(0,u)=0C(0,u)=D(0,u)=0, the equations are

∂TD=ξ22D2+(ρξiu−κ)D−u2+iu2,∂TC=iru+κθD.\partial_T D=\frac{\xi^2}{2}D^2+(\rho\xi iu-\kappa)D -\frac{u^2+iu}{2},\qquad \partial_T C=iru+\kappa\theta D.

The linear term in DD contains correlation, while the quadratic term comes from variance diffusion. The following closed-form solution is one way to solve those equations; checking ϕ(0)=1\phi(0)=1 and E[eXT]=S0erTE[e^{X_T}]=S_0e^{rT} provides basic convention and drift checks, though it does not verify all complex values.

β=κ−ρξiu,d=β2+ξ2(u2+iu),g=β−dβ+d,\beta=\kappa-\rho\xi iu,\quad d=\sqrt{\beta^2+\xi^2(u^2+iu)},\quad g=\frac{\beta-d}{\beta+d}, D=β−dξ21−e−dT1−ge−dT,C=iurT+κθξ2[(β−d)T−2log⁡1−ge−dT1−g].D=\frac{\beta-d}{\xi^2}\frac{1-e^{-dT}}{1-ge^{-dT}},\qquad C=iu rT+\frac{\kappa\theta}{\xi^2}\left[(\beta-d)T-2\log\frac{1-ge^{-dT}}{1-g}\right].

The complex square root and logarithm need a continuous convention. The e−dTe^{-dT} form reduces discontinuities in the original expression but does not remove the need to check branches, integrability and stability for the parameters and contours used. This difficulty is known as the Heston trap. The original paper is Heston (1993).

Fourier pricing uses ϕ\phi without reconstructing paths. COS approximates density on [a,b][a,b] with cosines and integrates its coefficients against payoff:

V0≈e−rT∑n=0N−1′Re⁡ ⁣[ϕX(un)e−iuna]Vn,un=nπb−a,Vn=2b−a∫abh(x)cos⁡(un(x−a)) dx.V_0\approx e^{-rT}\sum_{n=0}^{N-1}{}' \operatorname{Re}\!\left[\phi_X(u_n)e^{-iu_n a}\right]V_n, \quad u_n=\frac{n\pi}{b-a},\quad V_n=\frac{2}{b-a}\int_a^b h(x)\cos(u_n(x-a))\,dx.

The prime indicates that the zero term has half weight. It is useful to calculate the bounded put and recover the call by parity; direct call coefficients can suffer cancellation on wide windows. Large NN does not repair a window truncating probability. Fang and Oosterlee study COS convergence.

Carr-Madan damps the call in log-strike with α>0\alpha>0 and transforms the result. The integral uses ϕ(u−i(α+1))\phi(u-i(\alpha+1)); the corresponding exponential moment must exist. The lab’s quadrature evaluates the integral directly without claiming an FFT. Compare maximum frequency, step and damping, in addition to NN and window in COS.

With k=log⁡Kk=\log K, one convention for that inversion is

C(K)=e−αk−rTπ∫0∞Re⁡ ⁣[e−iukϕ(u−i(α+1))α2+α−u2+i(2α+1)u] du.C(K)=\frac{e^{-\alpha k-rT}}{\pi} \int_0^\infty \operatorname{Re}\!\left[ e^{-iuk}\frac{\phi(u-i(\alpha+1))} {\alpha^2+\alpha-u^2+i(2\alpha+1)u}\right]\,du.

The integrand contains the characteristic function of log⁡ST\log S_T, not a centered return; mixing conventions shifts price. In practice the integral is truncated and discretized: stability when extending the limit and refining the grid is a check, not a general proof of accuracy.

InteractiveCOS convergence
  • log₁₀ absolute error
6
Reference8.802661
Error N = 5124.95e-4
Absolute error for a synthetic Heston ATM call versus a COS reference with 1024 terms and L = 12. Index 0 to 6 represents N = 8 to 512 in powers of two; the reference is also numerical.

Simulation, jumps and SABR

Andersen’s QE scheme approximates the conditional law of vt+Δv_{t+\Delta} by matching its CIR mean and variance. For small ratio ψ=s2/m2\psi=s^2/m^2 it uses a Gaussian square; for large ψ\psi a mixture of point mass at zero and an exponential tail. This preserves nonnegative variance, but price discretization remains. The lab also measures discounted mean to detect martingale bias. The implemented variant applies no additional martingale correction. See Andersen (2008).

With e=e−κΔe=e^{-\kappa\Delta}, the conditional moments matched are

m=θ+(v−θ)e,s2=vξ2e(1−e)κ+θξ2(1−e)22κ.m=\theta+(v-\theta)e,\qquad s^2=\frac{v\xi^2e(1-e)}{\kappa}+ \frac{\theta\xi^2(1-e)^2}{2\kappa}.

The quadratic branch uses a(b+Z)2a(b+Z)^2 and the other assigns probability to zero and an exponential tail. Correlation enters the log-price step through vv and new variance. Matching the first two moments does not make the entire simulated transition exact.

In the Merton jump-diffusion model, Y∼N(μJ,δJ2)Y\sim N(\mu_J,\delta_J^2) is the log jump and NT∼Poisson⁡(λT)N_T\sim\operatorname{Poisson}(\lambda T). With kJ=E[eY−1]k_J=E[e^Y-1], compensation −λkJ-\lambda k_J preserves risk-neutral drift. Conditioning on jump count,

C=∑n=0∞e−λT(λT)nn!CBS ⁣(S0e−λkJT+n(μJ+δJ2/2),K,r,T,σ2+nδJ2/T).C=\sum_{n=0}^{\infty}e^{-\lambda T}\frac{(\lambda T)^n}{n!} C_{\rm BS}\!\left(S_0e^{-\lambda k_JT+n(\mu_J+\delta_J^2/2)}, K,r,T,\sqrt{\sigma^2+n\delta_J^2/T}\right).

The sum must be truncated with a tail bound or check. Jumps can produce pronounced wings at short maturities; risk-neutral parameters incorporate risk premiums and are not automatically physical frequencies. The source is Merton (1976).

Omitted Poisson mass alone does not bound call value without considering underlying growth. Since payoff is at most STS_T, a bound on discounted value of terms with NT>nN_T>n is S0P(N~>n)S_0P(\widetilde N>n), where N~\widetilde N is Poisson with mean λTeμJ+δJ2/2\lambda T e^{\mu_J+\delta_J^2/2}. This tilted law appears when each weight is multiplied by conditional mean STS_T. In the fit, the cell uses 40 terms and bounded parameters; that tail can be checked when changing bounds.

The SABR model describes a forward FF and stochastic volatility α\alpha: dF=αFβdW1dF=\alpha F^\beta dW_1, dα=ναdW2d\alpha=\nu\alpha dW_2, correlation ρ\rho. The asymptotic formula of Hagan and coauthors approximates Black volatility as a function of F,K,T,α,β,ρ,νF,K,T,\alpha,\beta,\rho,\nu; the code implements it and uses the continuous limit when K=FK=F. This is an expansion, not an exact price: near low strikes and for long maturities or extreme parameters it may fail and generate arbitrage.

For F,K>0F,K>0, set z=(ν/α)(FK)(1−β)/2log⁡(F/K)z=(\nu/\alpha)(FK)^{(1-\beta)/2}\log(F/K) and x(z)=log⁡[(1−2ρz+z2+z−ρ)/(1−ρ)]x(z)=\log[(\sqrt{1-2\rho z+z^2}+z-\rho)/(1-\rho)]. The approximation is

σB≈α(FK)(1−β)/2[1+(1−β)2ℓ2/24+(1−β)4ℓ4/1920]zx(z)[1+T((1−β)2α224(FK)1−β+ρβνα4(FK)(1−β)/2+(2−3ρ2)ν224)],\sigma_B\approx\frac{\alpha}{(FK)^{(1-\beta)/2} [1+(1-\beta)^2\ell^2/24+(1-\beta)^4\ell^4/1920]} \frac{z}{x(z)}\left[1+T\left( \frac{(1-\beta)^2\alpha^2}{24(FK)^{1-\beta}}+ \frac{\rho\beta\nu\alpha}{4(FK)^{(1-\beta)/2}}+ \frac{(2-3\rho^2)\nu^2}{24}\right)\right],

where ℓ=log⁡(F/K)\ell=\log(F/K) and z/x(z)→1z/x(z)\to1 near the money. The lab fixes β=0.5\beta=0.5 to reduce fit dimensionality; freeing β\beta can worsen identifiability.

Calibration and identifiability

Calibration minimizes discrepancies between quotes and model prices. Inverse-vega weighting approximates volatility error, though very small vega needs a floor to avoid huge weights. Bid-ask, synchronization, parameter bounds, multiple seeds and out-of-sample checking matter as much as the optimizer.

InteractiveThe calibration landscape
  • Height: price RMSE, capped at 2.5
1.5
0.04
Price RMSE at the selected point0.0002
RMSE of nine synthetic Heston prices on a κ and θ grid; v₀, ξ and ρ remain fixed at generating values. Height saturates to show the valley; sliders calculate error at the selected point. Drag to rotate.

A flat valley means several combinations can produce close prices in the observed set. A good fit does not guarantee unique parameters or good hedging. Check other maturities, volatility-sensitive instruments and stability across dates without treating those data as an automatic guarantee.

The residual Jacobian with respect to parameters helps locate weak directions: a small singular value means a combined change alters quotes little on the chosen scale. This is a local observation depending on weights, units and data; an error surface does not identify all minima of a five-dimensional problem. The chart deliberately fixes three parameters while the lab fits all five.

Smile dynamics and hedging

Smile dynamics affect effective delta. Sticky strike freezes volatility at each strike as the underlying moves; sticky delta approximately maintains shape in delta coordinates. These are scenario rules, not universal identities. Local diffusion or Heston predict shifts depending on state and parameterization, not always one of those extremes.

InteractiveMove the underlying
  • Sticky strike
  • Heston, fixed v₀
  • Local diffusion, MC
5
Sticky-strike delta0.6006
Heston delta with fixed v₀0.7024
Local-volatility delta, MC0.4850
Compare sticky strike, Heston with fixed v₀ and a local diffusion reconstructed from the initial Heston surface. Two calculated scenarios, S = 100 and 105, with T = 1. Deltas are central differences around S = K = 100. The following cell reproduces local diffusion and its approximations; curves include Monte Carlo and discretization error.

In Heston, if v0v_0 also moves when SS changes, scenario delta incorporates that covariation. In local diffusion the local-volatility function stays fixed in price-time coordinates; freezing the implied smile by strike would be another scenario. Choosing between models with the same current fit requires information about later dynamics and hedging, not just today’s RMSE.

Lab: Heston from start to finish

The first cell implements the characteristic function, COS, Carr-Madan quadrature and QE. The COS window is centered on exact mean log-price; its width is a chosen rule, not a tail-coverage guarantee. QE uses two CIR moments and an approximate log-price step.

[ ]Pricing and simulation methodsBrowser
import numpy as np
from scipy.special import ndtr
from scipy.integrate import simpson
from scipy.optimize import brentq

def bs(S,K,r,T,s):
 d1=(np.log(S/K)+(r+.5*s*s)*T)/(s*np.sqrt(T)); d2=d1-s*np.sqrt(T)
 return S*ndtr(d1)-K*np.exp(-r*T)*ndtr(d2)
def heston(u,S,r,T,p):
 v0,theta,kappa,xi,rho=p; iu=1j*u; beta=kappa-rho*xi*iu
 d=np.sqrt(beta*beta+xi*xi*(u*u+iu)); g=(beta-d)/(beta+d); e=np.exp(-d*T)
 C=iu*(np.log(S)+r*T)+kappa*theta/(xi*xi)*((beta-d)*T-2*np.log((1-g*e)/(1-g)))
 D=(beta-d)/(xi*xi)*(1-e)/(1-g*e)
 return np.exp(C+D*v0)
def cos_price(S,K,r,T,p,N=256,L=10):
 v0,theta,kappa,xi,rho=p
 c1=np.log(S/K)+r*T-.5*(theta*T+(v0-theta)*(1-np.exp(-kappa*T))/kappa)
 a,b=c1-L*np.sqrt(max(v0,theta)*T+.05*T*T),c1+L*np.sqrt(max(v0,theta)*T+.05*T*T)
 if a>=0: return S-K*np.exp(-r*T)
 u=np.arange(N)*np.pi/(b-a); c=a; d=min(0,b)
 psi=np.empty(N); psi[0]=d-c; psi[1:]=(np.sin(u[1:]*(d-a))-np.sin(u[1:]*(c-a)))/u[1:]
 chi=(np.exp(d)*(np.cos(u*(d-a))+u*np.sin(u*(d-a)))-np.exp(c)*(np.cos(u*(c-a))+u*np.sin(u*(c-a))))/(1+u*u)
 V=2*K/(b-a)*(psi-chi); V[0]*=.5
 put=np.exp(-r*T)*np.sum(np.real(heston(u,S,r,T,p)*np.exp(-1j*u*(np.log(K)+a)))*V)
 return put+S-K*np.exp(-r*T)
def carr(S,K,r,T,p,alpha=1.5,U=200,n=4097):
 u=np.linspace(0,U,n); z=u-1j*(alpha+1); phi=heston(z,S,r,T,p)
 den=alpha*alpha+alpha-u*u+1j*(2*alpha+1)*u
 return np.exp(-alpha*np.log(K)-r*T)/np.pi*simpson(np.real(np.exp(-1j*u*np.log(K))*phi/den),x=u)
def qe(S,r,T,p,N=100000,steps=100,seed=42):
 v0,theta,kappa,xi,rho=p; rng=np.random.default_rng(seed); dt=T/steps; v=np.full(N,v0); x=np.full(N,np.log(S)); exp=np.exp(-kappa*dt)
 K0=-rho*kappa*theta*dt/xi; K1=.5*dt*(kappa*rho/xi-.5)-rho/xi; K2=.5*dt*(kappa*rho/xi-.5)+rho/xi; K3=.5*dt*(1-rho*rho); K4=K3
 for _ in range(steps):
  m=theta+(v-theta)*exp; s2=v*xi*xi*exp*(1-exp)/kappa+theta*xi*xi*(1-exp)**2/(2*kappa); psi=s2/(m*m)
  z=rng.standard_normal(N); u=rng.random(N); vn=np.empty(N); low=psi<=1.5
  b2=2/psi[low]-1+np.sqrt(2/psi[low])*np.sqrt(2/psi[low]-1); a=m[low]/(1+b2); vn[low]=a*(np.sqrt(b2)+z[low])**2
  prob=(psi[~low]-1)/(psi[~low]+1); beta=(1-prob)/m[~low]; vn[~low]=np.where(u[~low]<=prob,0,np.log((1-prob)/(1-u[~low]))/beta)
  x+=r*dt+K0+K1*v+K2*vn+np.sqrt(K3*v+K4*vn)*rng.standard_normal(N); v=vn
 payoff=np.maximum(np.exp(x)-100,0)*np.exp(-r*T); return payoff.mean(),payoff.std(ddof=1)/np.sqrt(N),np.mean(np.exp(x-r*T))
[ ]Comparison and calibrationBrowser
p=(.04,.04,1.5,.5,-.7)
print('φ(0)',heston(0,100,.03,1,p),'φ(-i)',heston(-1j,100,.03,1,p),'forward',100*np.exp(.03))
for T in [.25,1,2]:
 for K in [80,100,120]: print(T,K,cos_price(100,K,.03,T,p),carr(100,K,.03,T,p))
print('QE',qe(100,.03,1,p))
from scipy.optimize import least_squares

from scipy.stats import poisson
print('cota de cola Merton en límites del ajuste',100*poisson.sf(39,3*np.exp(.2+.6**2/2)))

def merton(S,K,r,T,sig,lam,muj,sj):
 kappa=np.exp(muj+.5*sj*sj)-1; result=0.; weight=np.exp(-lam*T)
 for n in range(40):
  Sn=S*np.exp(-lam*kappa*T+n*(muj+.5*sj*sj)); sn=np.sqrt(sig*sig+n*sj*sj/T)
  result+=weight*bs(Sn,K,r,T,sn); weight*=lam*T/(n+1)
 return result

def sabr(F,K,T,alpha,beta,rho,nu):
 z=np.log(F/K); power=(F*K)**((1-beta)/2); zz=nu/alpha*power*z
 if abs(zz)<1e-7: ratio=1-.5*rho*zz+(2-3*rho*rho)*zz*zz/12
 else: ratio=zz/np.log((np.sqrt(1-2*rho*zz+zz*zz)+zz-rho)/(1-rho))
 den=power*(1+(1-beta)**2*z*z/24+(1-beta)**4*z**4/1920)
 correction=1+T*((1-beta)**2*alpha*alpha/(24*power*power)+rho*beta*nu*alpha/(4*power)+(2-3*rho*rho)*nu*nu/24)
 return alpha/den*ratio*correction

def iv(p,S,K,r,T): return brentq(lambda s:bs(S,K,r,T,s)-p,1e-4,3)

# Synthetic Heston quotes with fixed, bounded noise in price; calibrate five params.
rng=np.random.default_rng(281616); times=[.5,1,2]; strikes=[80,90,100,110,120]; pairs=[(T,K) for T in times for K in strikes]
true=(.04,.04,1.5,.5,-.7); clean=np.array([cos_price(100,K,.03,T,true,96,10) for T,K in pairs]); obs=clean+rng.uniform(-.02,.02,len(clean))
weights=np.array([max(.5,100*np.sqrt(T)*np.exp(-.5*((np.log(100/K)+(.03+.5*.2**2)*T)/(.2*np.sqrt(T)))**2)/np.sqrt(2*np.pi)) for T,K in pairs])
def residual(p):return np.array([cos_price(100,K,.03,T,p,96,10) for T,K in pairs])/weights-obs/weights
for x in [[.03,.06,1,.3,-.3],[.06,.03,2.5,.7,-.8]]:
 fit=least_squares(residual,x,bounds=([.005,.005,.2,.1,-.95],[.2,.2,4,1,.95]),max_nfev=300,xtol=1e-9,ftol=1e-9,gtol=1e-9)
 print('Heston fit',np.round(fit.x,5),'RMSE vols approx',np.sqrt(np.mean(fit.fun**2)))
# Three independent noise draws: fit separate Merton or SABR to each maturity.
for day in range(3):
 for T in [.25,1.]:
  Ks=np.linspace(80,120,9); clean=np.array([merton(100,K,.03,T,.17,.8,-.08,.18) for K in Ks]); obs=clean+rng.uniform(-.01,.01,len(Ks)); vols=np.array([iv(P,100,K,.03,T) for K,P in zip(Ks,obs)]); F=100*np.exp(.03*T)
  fm=least_squares(lambda p: np.array([merton(100,K,.03,T,*p) for K in Ks])-obs,[.16,.6,-.05,.15],bounds=([.05,.01,-.4,.01],[.5,3,.2,.6]),max_nfev=200)
  fs=least_squares(lambda p:np.array([sabr(F,K,T,p[0],.5,p[1],p[2]) for K in Ks])-vols,[2.,-.3,.4],bounds=([.05,-.95,.01],[10,.95,3]),max_nfev=200)
  merton_vols=np.array([iv(merton(100,K,.03,T,*fm.x),100,K,.03,T) for K in Ks])
  rmse_m=np.sqrt(np.mean((merton_vols-vols)**2));rmse_s=np.sqrt(np.mean(fs.fun**2))
  print('dia',day,'T',T,'Merton',np.round(fm.x,4),'SABR',np.round(fs.x,4),'RMSE vol común Merton/SABR',round(rmse_m,6),round(rmse_s,6))

In this run, the nine COS and Carr-Madan prices differ by at most 4.58e-7; the one-year ATM call is approximately 8.80266. QE with 100,000 paths and 100 steps gives 8.76124 with standard error 0.03166 and discounted mean 99.89848 versus 100: the discrepancy includes discretization and noise and does not prove exact equivalence. Two optimization seeds lead to very close parameters in this example; that does not prove uniqueness. Fifteen synthetic prices with uniform noise amplitude 0.02 and vega weights floored at 0.5 are calibrated.

The second code section separately fits Merton and SABR to three Merton price-noise realizations. For the fit bounds and maximum one-year maturity, the tail bound after 40 terms is approximately 8.29e-23 price units. The fitting objectives differ: Merton minimizes price error and SABR volatility error. To compare them, Merton prices are inverted to Black volatility and RMSE is calculated for both over the same nine options on each day and maturity. For example, at one year estimated Merton intensity varies approximately between 0.76 and 1.00 despite a small fitting error. These are not real days or empirical evidence: this is a sensitivity test to known perturbations.

In the first realization, common volatility RMSE for Merton and SABR is respectively 0.000588 and 0.001168 at three months, and 0.000185 and 0.000259 at one year. The generating surface belongs to Merton; this comparison does not show Merton fits other surfaces better. Other realizations and parameters appear in the output.

[ ]Truncated Euler and time resolutionBrowser
def euler(S,r,T,p,N=100000,steps=100,seed=42):
    v0,theta,kappa,xi,rho=p; rng=np.random.default_rng(seed); dt=T/steps
    v=np.full(N,v0); x=np.full(N,np.log(S)); negative=0
    for _ in range(steps):
        z=rng.standard_normal(N); z2=rng.standard_normal(N); vp=np.maximum(v,0)
        x+=(r-.5*vp)*dt+np.sqrt(vp*dt)*(rho*z+np.sqrt(1-rho*rho)*z2)
        v+=kappa*(theta-vp)*dt+xi*np.sqrt(vp*dt)*z
        negative+=int(np.count_nonzero(v<0))
    payoff=np.exp(-r*T)*np.maximum(np.exp(x)-100,0)
    return payoff.mean(),payoff.std(ddof=1)/np.sqrt(N),negative/(N*steps)
for steps in [25,100,400]:
    print('pasos',steps,'Euler',euler(100,.03,1,p,N=20000,steps=steps),
          'QE',qe(100,.03,1,p,N=20000,steps=steps))

Euler uses full truncation in coefficients, but the auxiliary state can be negative; the third value counts that frequency. QE figures include discounted mean. Refining the step can reduce bias, while Monte Carlo error depends on path count; method seeds and samples do not produce a paired comparison.

Reconstruct the smile comparison

The cell derives a Dupire grid from Heston prices in the first cell. Finite differences in price and time amplify tail error: quotients outside variance interval [0.0025,1] are discarded and valid values interpolated in strike, with constant extension at endpoints. Volatility 0.2 is used until t = 0.02 and boundaries extended for states outside [60,150]. Local diffusion is simulated with 20,000 paths and 80 steps, using common random numbers for four initial values. This is an explicit approximation, not exact surface equality. Columns show strike, price, implied volatility, price standard error and, for S = 100, reference Heston price. The central difference using S = 99 and 101 approximates local delta at K = 100.

[ ]Local diffusion from HestonBrowser
p=(.04,.04,1.5,.5,-.7); S=100.;r=.03; Ks=np.linspace(60,150,91); ts=np.linspace(.02,1.,50); grid=np.empty((len(ts),len(Ks))); invalid=0
def cos_many(K,T):
 v0,theta,kappa,xi,rho=p; K=np.asarray(K)
 c1=np.log(S/K)+r*T-.5*(theta*T+(v0-theta)*(1-np.exp(-kappa*T))/kappa)
 width=12*np.sqrt(max(v0,theta)*T+.05*T*T); a=c1-width; b=c1+width
 u=np.arange(256)[None,:]*np.pi/(b-a)[:,None]; aa=a[:,None]; d=np.minimum(0,b)[:,None]
 psi=np.empty_like(u);psi[:,0]=(d-aa)[:,0];psi[:,1:]=(np.sin(u[:,1:]*(d-aa))-np.sin(u[:,1:]*(aa-aa)))/u[:,1:]
 chi=(np.exp(d)*(np.cos(u*(d-aa))+u*np.sin(u*(d-aa)))-np.exp(aa))/(1+u*u)
 V=2*K[:,None]/(b-a)[:,None]*(psi-chi);V[:,0]*=.5
 put=np.exp(-r*T)*np.sum(np.real(heston(u,S,r,T,p)*np.exp(-1j*u*(np.log(K)[:,None]+aa)))*V,axis=1)
 return np.where(a>=0,S-K*np.exp(-r*T),put+S-K*np.exp(-r*T))
for i,T in enumerate(ts):
 dk=.5;dt=.005
 c=cos_many(Ks,T);kp=cos_many(Ks+dk,T);km=cos_many(Ks-dk,T)
 ct=(cos_many(Ks,T+dt)-cos_many(Ks,T-dt))/(2*dt)
 ck=(kp-km)/(2*dk);ckk=(kp-2*c+km)/(dk*dk)
 with np.errstate(divide='ignore',invalid='ignore'): local=np.where(ckk>1e-8,(ct+r*Ks*ck)/(.5*Ks*Ks*ckk),np.nan)
 valid=np.isfinite(local)&(local>=.0025)&(local<=1.); invalid+=np.count_nonzero(~valid)
 grid[i]=np.sqrt(np.where(valid,local,np.nan))
 # interpolación en strike y extensión constante en los extremos
 valid=np.isfinite(grid[i]); grid[i]=np.interp(Ks,Ks[valid],grid[i,valid])
print('invalid cells',invalid,'/',grid.size,'range',grid.min(),grid.max())
N=20000;steps=80;dt=1/steps;rng=np.random.default_rng(281616);z=rng.standard_normal((steps,N))
spots=np.array([99.,100.,101.,105.]); paths=np.broadcast_to(spots[:,None],(4,N)).copy(); boundary=np.zeros(4,int)
for i in range(steps):
 t=(i+.5)*dt; boundary+=np.sum((paths<60)|(paths>150),axis=1)
 if t<.02: vol=np.full_like(paths,.2)
 else:
  j=min(np.searchsorted(ts,t)-1,len(ts)-2); w=(t-ts[j])/(ts[j+1]-ts[j])
  vol=(1-w)*np.interp(paths,Ks,grid[j])+w*np.interp(paths,Ks,grid[j+1])
 paths*=np.exp((r-.5*vol*vol)*dt+vol*np.sqrt(dt)*z[i])
for row,spot in enumerate(spots):
 S0=paths[row]
 Ks2=np.arange(75,131,5); vals=[]
 for K in Ks2:
  payoff=np.exp(-r)*np.maximum(S0-K,0);c=payoff.mean();lo,hi=.001,2.
  for j in range(40):
   m=(lo+hi)/2
   if bs(spot,K,r,1,m)<c:lo=m
   else:hi=m
  vals.append((K,c,(lo+hi)/2,payoff.std(ddof=1)/np.sqrt(N),cos_price(100,K,r,1,p) if spot==100 else 0))
 print('spot',spot,'boundary fraction',boundary[row]/(N*steps),'discounted mean',np.exp(-r)*S0.mean());print('result',vals)

The run replaces 206 of 4550 cells and, with initial S 100, 1.13% of states per step use boundary extension. The local ATM call is 8.86695 with standard error 0.07090 versus Heston’s 8.80266. With S = 105, 0.56% use that extension. Approximate local delta is 0.4850, calculated with the same innovations for both shifts; these diagnostics do not certify the wings or real market dynamics.

Exercises

NumericCheck Feller
With κ = 1.5 and θ = 0.04, calculate 2κθ. Compare with ξ² when ξ = 0.5.
ProofCondition on jump count
Prove: Derive the Merton series by conditioning on jump count.
0
Log jumps are independent normal variables with mean μJ and variance δJ².

Step 1 of 3. What is the log-price distribution conditional on N = n?

QuizSlope and correlation
Which Heston parameter primarily controls smile asymmetry?
QuizChoose between equivalent fits
Two Heston parameter sets fit today's surface equally. What additional evidence helps choose?
CodeGeneric COS
Implement cos_price(cf,S,K,r,T,N,L) for the characteristic function of log S_T. Estimate the first two cumulants by differences at u = 0.001; use the mean ± L standard deviations window, COS put and parity. The test uses GBM at several strikes and maturities.
def cos_price(cf,S,K,r,T,N,L):
  raise NotImplementedError()
Shift+Enter to run

Ideas to remember

Heston and Merton introduce different dynamics that can fit similar prices. COS and Carr-Madan require checking truncation and complex branches; QE preserves nonnegativity of approximate variance but does not eliminate all bias. Calibration is an inverse problem and today’s smile does not certify future hedging.