Stochastic Local Volatility in QuantLib
J. Göttker-Schnetmann, K. Spanderen
QuantLib User Meeting 2014 Düsseldorf 2014-12-06
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 1 / 41 Heston Stochastic Local Volatility
Fokker-Planck Equations Square Root Process Boundary Conditions Coordinate and Density Transformations
Calibration
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 2 / 41 Local Volatility [Dupire 1994]
Local Volatility σLV (S, t) as function of spot level St and time t:
1 d ln S = r − q − σ2 (S, t) dt + σ (S, t)dW t t t 2 LV LV t ∂C ∂C + (rt − qt ) K + qt C σ2 (S, t)= ∂T ∂K LV K 2 ∂2C 2 ∂K 2 K =S,T =t
Consistent with option market prices. Model is often criticized for its unrealistic volatility dynamics. Dupire formula is mathematically appealing but also unstable.
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 3 / 41 Stochastic Volatility [Heston 1993]
Stochastic volatility given by a square-root process:
1 √ d ln S = r − q − ν dt + ν dW S t t t 2 t t t √ ν dνt = κ (θ − νt ) dt + σ νt dWt ν S ρdt = dWt dWt
Semi-analytical solution for European call option prices:
−(rt −qt )T C(S0, K , ν0, T ) = SP1 − Ke P2 Z ∞ " −iu ln K # 1 1 e φj (S0, K , ν0, T , u) Pj = + < du 2 π 0 iu
More realistic volatility dynamics. Does often not exhibit enough skew for short dated expiries.
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 4 / 41 Example: Differences in δ and γ
The implied and local volatility surface is derived from the Heston model and therefore the option prices between all models match. S0 = 5000, κ = 5.66, θ = 0.075, σ = 1.16, ρ = −0.51, ν0 = 0.19, T = 1.7 − 4
Black-Scholes 3*10 Heston Heston Mean Variance Local Volatility 0.8 1.0 − 4 2*10 δ γ − 4
Black-Scholes Heston
0.2 0.4 0.6 Heston Mean Variance Local Volatility 0 1*10
2000 3000 4000 5000 6000 7000 8000 2000 3000 4000 5000 6000 7000 8000 Strike Strike Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 5 / 41 Heston Stochastic Local Volatility
Add leverage function L(St , t) and mixing factor η:
1 √ d ln S = r − q − L(S , t)2ν dt + L(S , t) ν dW S t t t 2 t t t t t √ ν dνt = κ (θ − νt ) dt + ησ νt dWt ν S ρdt = dWt dWt
Leverage L(xt , t) is given by probability density p(St , ν, t) and s R σ (S , t) + p(St , ν, t)dν L(S , t) = LV t = σ (S , t) R t p LV t R νp(S , ν, t)dν E[νt |S = St ] R+ t Mixing factor η tunes between stochastic and local volatility.
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 6 / 41 Cheat Sheet: Link between SDE and PDE
Starting point is a multidimensional SDE of the form:
dxt = µ(xt , t)dt + σ(xt , t)dW t
Feynman-Kac: price of a derivative u(xt , t) with boundary condition u(xT , T ) at maturity T is given by:
n n X 1 X T ∂t u + µi ∂x u + σσ ∂x ∂x u − ru = 0 k 2 kl k l k=1 k,l=1
Fokker-Planck: time evolution of the probability density function p(xt , t) with the initial condition p(x, t = 0) = δ(x − x0) is given by:
n n X 1 X h T i ∂t p = − ∂x [µi p] + ∂x ∂x σσ p k 2 k l kl k=1 k,l=1
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 7 / 41 Backward Feynman-Kac Equation
The SLV model leads to following Feynman-Kac equation for a function u : R × R≥0 × R≥0 → R, (x, ν, t) 7→ u(x, ν, t): 1 1 0 = ∂ u + L2ν∂2u + η2σ2ν∂2u + ησνρL∂ ∂ u t 2 x 2 ν x ν 1 + r − q − L2ν ∂ u + κ (θ − ν) ∂ u − ru 2 x ν
PDE can be solved using either Implict scheme (slow) or more advanced operator splitting schemes like modified Craig-Sneyd or Hundsdorfer-Verwer in conjunction with damping steps (fast). Implementation is mostly harmless, extend FdmHestonOp.
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 8 / 41 Forward Fokker-Planck Equation
The corresponding Fokker-Planck equation for the probability density p : R × R≥0 × R≥0 → R≥0, (x, ν, t) 7→ p(x, ν, t) is: 1 h i 1 ∂ p = ∂2 L2νp + η2σ2∂2 [νp] + ησρ∂ ∂ [Lνp] t 2 x 2 ν x ν 1 −∂ r − q − L2ν p − ∂ [κ (θ − ν) p] x 2 ν
Numerical solution of the PDE is cumbersome due to difficult boundary conditions and the Dirac delta distribution as the initial condition. PDE can be efficiently solved using operator splitting schemes, preferable the modified Craig-Sneyd scheme
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 9 / 41 Square Root Process
Main issues of the implementation are caused by the square root process: √ dνt = κ(θ − νt )dt + σ νt dW It has the following Fokker-Planck equation for the probability density p : R≥0 × R≥0 → R≥0, (ν, t) 7→ p(ν, t):
σ2 ∂ p = ∂2 [νp] − ∂ [κ(θ − ν)p] t 2 ν ν
The stationary probability density pˆ(ν) with ∂t pˆ(ν) = 0 is: 2κθ α pˆ(ν) = βανα−1 exp(−βν)Γ(α)−1, α = , β = σ2 θ
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 10 / 41 Stationary Probability Density
Stationary Distribution with θ=0.25 ∞ if α < 1 6 −1 α=2.0 lim pˆ(ν) = θ if α = 1 α=1.2 ν→0 α=1.0 0 if α > 1 α=0.5 3 4 5 ( ν ) ^ The square root process νt p is strictly positive if the Feller Condition α > 1 is met. 0 1 2
0.0 0.2 0.4 0.6 0.8
ν
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 11 / 41 Boundary Condition
The probability weight within [νmin, νmax ] of p(ν, t) is evolving by:
Z νmax Z νmax 2 σ 2 ∂t dνp = dν ∂ν [νp] − ∂ν [κ(θ − ν)p] νmin νmin 2 In order to avoid leaking of probability we enforce:
ν Z νmax 2 max σ ∂t dνp = 0 ⇒ ∂ν [νp] − [κ(θ − ν)p] = 0 2 νmin νmin 2 σ ⇒ ∂ν [νp] − [κ(θ − ν)p] = 0 2 ν=νmin,νmax
Zero Flux Boundary Condition
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 12 / 41 Discretization
On a non-uniform grid {z1,..., zn} the two-sided approximation of ∂z f is:
2 2 2 2 hi−i fi+1 + (hi − hi−1)fi − hi fi−1 ∂z f (zi ) ≈ hi−1hi (hi−1 + hi ) h f − f h f − f = i−1 i+1 i + i i i−1 hi−1 + hi hi hi−1 + hi hi−1
With hi := zi+1 − zi and fi := f (zi ). The second order derivative is approximated by:
h f − (h + h )f + h f ∂2 ( ) ≈ i−i i+1 i−1 i i i i−1 z f zi 1 2 hi−1hi (hi−1 + hi )
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 13 / 41 Discretization
Sort by factors of fi , set
ζi := hi hi−1 p ζi := hi (hi−1 + hi ) m ζi := hi−1(hi−1 + hi )
then: h (h − h ) h ∂ f (z ) ≈ i−i f + i i−1 f − i f z i p i+1 ζ i ζm i−1 ζi i i 2 2 2 ∂2f (z ) ≈ f − f + f z i p i+1 ζ i ζm i−1 ζi i i
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 14 / 41 Discretization
A general partial differential equation of the form
2 ∂t f = A(z)∂z f + B(z)∂z f + C(z)f
has therefore the spacial discretization:
2A + B h −2A + B (h − h ) ∂ f (z ) = i i i−i f + i i i i−1 + C f t i p i+1 ζ i i ζi i 2Ai − Bi hi + m fi−1 ζi =: γi fi+1 + βi fi + αi fi−1
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 15 / 41 Discretization
This is interpreted as a tridiagonal transfer matrix T with diagonal βi , upper diagonal γi , and lower diagonal αi : β1 γ1 0 ... α β γ 0 ... 2 2 2 0 α β γ 0 ... 3 3 3 T := . . . . . 0 ...... 0 . . αn−1 βn−1 γn−1 αn βn
Then f1 f1 . . ∂t . = T . fn fn
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 16 / 41 Boundary Condition
Add z0 below the lower boundary and zn+1 above the upper boundary to the grid. The zero flux condition takes the general form
! [∂z A(z, t)f + B(z, t)f ] = 0 z=z0,zn+1 Lower Boundary: The partial derivative is discretized by a second order forward differentiation, so that all terms are given by grid points
2 2 2 2 −h0f2 + (h1 + h0) f1 − ((h1 + h0) − h0)f0 ∂z f (z0) ≈ h0h1(h1 + h0) h (h + h ) (2h + h ) = − 0 f + 0 1 f − 0 1 f p 2 ζ 1 ζm 0 ζ1 1 1
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 17 / 41 Boundary Condition
The general zero-flux boundary condition is therefore discretized at the lower boundary as
h (h + h ) (2h + h ) 0 = − 0 A f + 0 1 A f + − 0 1 A + B f p 0 2 ζ 0 1 ζm 0 0 0 ζ1 1 1 =: c1f2 + b1f1 + a1f0 c1 b1 ⇒ f0 = − f2 − f1 a1 a1
∂t f1 = γ1f2 + β1f1 + α1f0 c1 b1 = (γ1 − α1 )f2 + (β1 − α1 )f1 a1 a1 → modification of the transfer matrix.
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 18 / 41 Non-Uniform Meshes
Non-uniform meshes are a key component [Tavella & Randall 2000]
Define coordinate transformation Y = Y () for n critical points Bk with density factors βk
1 " n #− 2 0.06 0.08 dY () X −2
= A J () ν d k k=1 q 2 2 Jk () = β + (Y () − Bk )
Y (0) = Ymin
Y (1) = Ymax 0.00 0.02 0.04 2 3 4 5 6 7 ODE solver is based on Peter’s x = log(S) Runge-Kutta implementation. Example: x0 = ln(100), ν0 = 0.05, Feller constraint is fulfilled
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 19 / 41 Loss of Probability
Time evolution of the stationary distribution with zero flux condition.
Z x 0
P(x) = pˆ(ν)dν 10 −∞ − 1
−1 10 νmin = P (0.01)
−1 − 2 νmax = P (0.99) 10 Z νmax − 3
pdˆ ν = 0.98 10 νmin − 4 10 Integral Error Integral error after evolving − 5 for one year: 10 − 6
Z νmax 10 grid size: 100 Feller Constraint grid size: 1000 p(ν, t = 1y)dν − 0.98 − 7 νmin 10 0.2 0.4 0.6 0.8 1.0 1.2 1.4
σ
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 20 / 41 Transformed Density
Recap: Stationary distribution:
pˆ(ν) = βανα−1 exp(−βν)Γ(α)−1
Remove divergence following Lucic [2] by using
q = ν1−αp σ2 2κ2θ ⇒ ∂ q = ν∂2q + κ(ν + θ)∂ q + q t 2 ν ν σ2 This equation has the stationary solution
qˆ(ν) = βα exp(−βν)Γ(α)−1
which converges to βαΓ(α)−1 as ν → 0
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 21 / 41 Transformed Probability Density
Time evolution of the transformed distribution with zero flux condition. 0 10 − 1
10 orig. FPE, grid size: 100 orig. FPE, grid size: 1000
− 2 trans. FPE, grid size: 100
10 trans. FPE, grid size: 1000 − 3 10 − 4 10 Integral Error − 5 10 − 6 10
Feller Constraint − 7 10
0.5 1.0 1.5 2.0
σ
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 22 / 41 Log Coordinates
Apply Itô’s lemma to z = log ν:
σ2 1 1 dz = ((κθ − ) − κ)dt + σ √ dW 2 ν ν
Fokker-Planck equation for the probability distribution f : R × R≥0 → R≥0, (z, t) 7→ f (z, t) (ν = exp(z)):
σ2 1 σ2 1 ∂ f (z, t) = −∂ ((κθ − ) − κ)f + ∂2( f ) t z 2 ν z 2 ν Stationary solution:
ˆf (z) = βα exp(zα) exp(−β exp(z))Γ(α)−1 = νpˆ(ν)
ˆf converges to 0 as z → −∞
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 23 / 41 Log Coordinates
Time evolution of log probability density with zero flux condition 0 10 log FPE, grid size: 100 log FPE, grid size: 1000 − 1 10 − 2 10 − 3 10 − 4 10 Integral Error − 5 10 − 6 10
Feller Constraint − 7 10
0.5 1.0 1.5 2.0
σ
−1 νmin = min 0.001, F (0.01)
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 24 / 41 Intermediate Results
Proper implementation of the zero flux boundary condition is not enough to get a stable scheme.
Transformation of the PDE in log coordinates leads to a less poisonous problem.
Non-Uniform meshers are a key component for success.
→ all in all, mostly harmless . Time for another dimension ,
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 25 / 41 Zero Flux Boundary Condition in two Dimensions
Adding the stock process to the picture complicates matters a bit. Probability density has a second variable x = log S, and the Fokker-Planck equation reads
2 ∂t f = ∂z A(z, x, t)f + ∂z B(z, x, t)f + ∂z ∂x ρC(z, x, t)f + powers of ∂x
Stretching the argument above a bit1 we arrive at the boundary condition
! [∂z A(z, x, t)f + B(z, x, t)f + ρ∂x C(z, x, t)f ] = 0 z=z0,z1
1Can be made rigorous [2] Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 26 / 41 SLV Fokker-Planck: Natural Coordinates
ν √ dx = (r − q − t )dt + ν L(x, t)dW x t t t 2 t t √ ν dνt = κ(θ − νt )dt + ησ νt dWt x ν ρdt = dWt dWt Fokker-Planck equation: 1 h i 1 ∂ p = ∂2 L2νp + η2σ2∂2 [νp] + ησρ∂ ∂ [Lνp] t 2 x 2 ν x ν 1 −∂ r − q − L2ν p − ∂ [κ (θ − ν) p] x 2 ν The zero flux condition takes the form ∀x : 2 2 σ σ ν∂νp + κ(ν − θ) + p + ρνσ∂x Lp = 0 2 2 ν=ν0,ν=νn+1
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 27 / 41 SLV Fokker-Planck: Transformed Density q = v 1−αp
Fokker-Planck equation for q = ν1−αp
ν ν 2κθ ∂ q = ∂2L2q + (−r + q )∂ q + ∂ ( L2 + ρσ L)q t 2 x t t x x 2 σ2 σ2 2κ2θ + ν∂2q + κ(ν + θ)∂ q + q 2 ν ν σ2 +ρσν∂x ∂νLq
The zero flux condition takes the form ∀x :
2 σ ν∂νq + κνq + ρνσ∂x Lq = 0 2 ν=ν0,ν=νn+1
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 28 / 41 SLV Fokker-Planck: Log Coordinates
ν √ dx = (r − q − t )dt + ν L(x, t)dW x t t t 2 t t σ2 1 1 dz = ((κθ − ) − κ)dt + ησ √ dW ν t 2 ν ν t x ν ρdt = dWt dWt Fokker-Planck equation: 1 h i η2σ2 1 ∂ f = ∂2 L2νf + ∂2 f + ησρ∂ ∂ [Lf ] t 2 x 2 z ν x z 1 σ2 1 −∂ r − q − L2ν f − ∂ (κθ − ) − κf x 2 z 2 ν The zero-flux boundary condition is 2 2 η σ 1 θ ! ∂z f − κ(1 − )f + ρσ∂x Lf = 0 2 ν ν ν=ν0,ν=νn+1
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 29 / 41 SLV Fokker-Planck: Implementation
Example log coordinates:
1 h i η2σ2 1 ∂ f = ∂2 L2νf + ∂2 f + ησρ∂ ∂ [Lf ] t 2 x 2 z ν x z 1 σ2 1 −∂ r − q − L2ν f − ∂ (κθ − ) − κf x 2 z 2 ν
ν η2σ2 1 ∂ f = ∂2L2f + ∂2f + ησρ∂ ∂ Lf t 2 x 2 ν z x z ν σ2 1 κθ +(−r + q)∂ f + ∂ L2f + (−κθ − ) + κ ∂ f + f x 2 x 2 ν z ν
Use multiplication of derivative operators with L on the right hand side, added method multR to TripleBandBinearOp (saves some terms).
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 30 / 41 Start Condition: Dirac Delta Distribution
To begin with the Dirac delta distribution need to be regularized. Approximation for small ∆t based on
σ (x , 0) L(x, t) = LV √t=0 = const ∀t ∈ [0, ∆t] ν0
1 Exact solution is known for ρ = 0
2 One Euler Step based on the SDE leads to bivariate Gaussian distribution
3 Semi-Analytical solution for exact sampling [Brodie, Kaya 2006]
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 31 / 41 Calibration
Start with a a calibrated Local Volatility Model σLV (xt , t) and calibrated Heston Model (ν0, θ, κ, σ, ρ)
Recap: Leverage L(xt , t) is given by s R σ (x , t) + p(xt , ν, t)dν L(x , t) = LV t = σ (x , t) R t p LV t R νp(x , ν, t)dν E[νt |x = xt ] R+ t
Start condition: p(x, ν, 0) = δ(x − x0)δ(ν − nu0)
σLV (xt=0, 0) ⇒ L(xt=0, 0) = √ ν0
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 32 / 41 Calibration
Iterative Scheme:
1 Use Fokker-Planck equation to get from
p(x, ν, t) → p(x, ν, t + ∆t)
assuming a piecewise constant leverage function L(xt , t) in t
2 Calculate leverage function at t + ∆t: s R p(x, ν, t + ∆t)dν L(x, t + ∆t) = σ (x, t + ∆t) R+ LV R νp(x, ν, t + ∆t)dν R+
3 Set t := t + ∆t 4 If t is smaller than the final maturity goto 1
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 33 / 41 Calibration Example
Motivation: Set-up extreme test case for the LSV calibration
Feller condition is strongly violated with α = 0.6 Implied volatility surface of the Heston and the local volatility model differ significantly.
Local Volatility: σLV (x, t) ≡ 30% Heston Parameters: √ 2 S0 = 100, ν0 = 24.5%, κ = 1, θ = ν0, σ = 0.2, ρ = −75% Use log coordinates and modified Craig-Sneyd scheme
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 34 / 41 Calibration Example: Heston Implied Volatility Surface
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 35 / 41 Calibration Example: Round Trip
Quality of calibration is tested by the round trip error
Fokker-Planck step: Calibrate the leverage function L(x, t) Feyman-Kac step: Calculate European option prices under resulting LSV model and back out implied volatility surface Show differences w.r.t. expected value of
σimpl (K , t) = σLV (S, t) = 30%
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 36 / 41 Calibration Example: LSV Implied Volatility Surface
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 37 / 41 Calibration Example: Leverage Function L(St , t)
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 38 / 41 Conclusion: Heston Local Volatility in QuantLib
Backward Feyman-Kac solver Forward Fokker-Planck solver Zero-Flux boundary condition natural and log coordinates, transformed probability density
Non-uniform meshers are a key factor for success
Heston Local Volatility calibration
Round trip errors are around 5bp in vols for extreme case
Repository: https://github.com/jschnetm/quantlib/tree/slv/QuantLib
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 39 / 41 Literature
William Feller. Two singular diffusion problems. The Annals of Mathematics, 54(1):173–182, 1951. Vladimir Lucic. Boundary conditions for computing densities in hybrid models via PDE methods. Stochastics, 84(5-6):705–718, 2012. Yu Tian, Zili Zhu, Geoffrey Lee, Fima Klebaner, and Kais Hamza. Calibrating and Pricing with a Stochastic-Local Volatility Model., 2014. http://ssrn.com/abstract=2182411.
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 40 / 41 Disclaimer
The views expressed in this presentation are the personal views of the speakers and do not necessarily reflect the views or policies of current or previous employers.
Göttker-Schnetmann, Spanderen Towards SLV in QuantLib QuantLib User Meeting 41 / 41