VibratoMonteCarlo.jl

Differentiable MonteCarlo Methods.
View on GitHub Star

About this Package

VibratoMonteCarlo.jl is a Julia package containing some useful Financial functions for sensitivity computation.
VibratoMonteCarlo.jl is built on top of FinancialMonteCarlo.jl and FinancialFFT.jl. Standard montecarlo methods lacks of differentiability, which makes automatic differentiation useless. The main aim of this package is to provide a feasible way to compute sensitivities of any order for various types of payoffs using montecarlo methods.

The implementation for Vibrato Montecarlo is heavily based on the Master Thesis of Nicola Scaramuzzino (that is me) and the subsequent development.

The basic settings

Let's assume we have an underlying stock price varying as a stochastic process called StS_t and let's assume without loss of generality that St>0S_t>0 a.e..
In that case we can define as XtX_t the following:

Xt=log(St)X_t=\log(S_t)

Let's assume we want to price and compute the sensitivities of a european option with maturity TT and payoff ϕ\phi.

We can express the price of such option as:

V0=E(ϕ(ST))V_0=\mathbb{E}(\phi(S_T))

or, in function of XTX_T:

V0=E(Φ(XT))V_0=\mathbb{E}(\Phi(X_T))

Where:

Φ(x)=ϕ(ex)\Phi(x)=\phi(e^x)

Pathwise Method

Since:

V0=E(Φ(XT))V_0=\mathbb{E}(\Phi(X_T)) θV0=θE(Φ(XT))=E(Φ(XT)XTXTθ)\partial_\theta V_0=\partial_\theta \mathbb{E}(\Phi(X_T)) = \mathbb{E}(\dfrac{\partial \Phi(X_T)}{\partial X_T}\dfrac{\partial X_T}{\partial \theta})

Where the following is called tangent process:

Yt=XtθY_t=\dfrac{\partial X_t}{\partial \theta}

In case of a European Option with maturity TT and strike price KK:

Φ(x)=max(exK,0)\Phi(x) = max(e^x-K,0)

and:

Φ(x)x=ex1ex>K(x)\dfrac{\partial \Phi(x)}{\partial x} = e^x \mathbb{1}_{ e^{x} > K } (x)

Hence:

θV0=E(Φ(XT)XTXTθ)\partial_\theta V_0=\mathbb{E}(\dfrac{\partial \Phi(X_T)}{\partial X_T}\dfrac{\partial X_T}{\partial \theta})

Unfortunately this method does not provide usefull results for binary options or for n-th order sensitivities, indeed in case of binary options we have:

Φ(x)=1(x)\Phi(x)=\mathbb{1}(x)

Hence:

xΦ(x)=0\partial_x \Phi(x)=0

Likelihood Ratio Method

Let's assume we have an underlying stock price varying as a stochastic process called StS_t and let's assume without loss of generality that St>0S_t>0 a.e..
In that case we can define as XtX_t the following:

Xt=log(St)X_t=\log(S_t)

Let's assume we want to price and compute the sensitivities of a european option with maturity TT and payoff ϕ\phi.

We can express the price of such option as:

V0=E(ϕ(ST))V_0=\mathbb{E}(\phi(S_T))

or, in function of XTX_T:

V0=E(Φ(XT))V_0=\mathbb{E}(\Phi(X_T))

Where:

Φ(x)=ϕ(ex)\Phi(x)=\phi(e^x)

If we develop the integral:

V0=E(Φ(XT))=RΦ(x)f(x)dxV_0=\mathbb{E}(\Phi(X_T))=\int_{\mathbb{R}} \Phi(x) f(x) dx

where the following is the density of the log yield:

f(x)=fXT(x)f(x)=f_{X_T}(x)

If we differentiate for a generic parameter θ\theta:

θV0=θRΦ(x)f(x,θ)dx=RΦ(x)θf(x,θ)dx\partial_\theta V_0=\partial_\theta \int_{\mathbb{R}} \Phi(x) f(x,\theta) dx = \int_{\mathbb{R}} \Phi(x) \partial_\theta f(x,\theta) dx

or:

θV0=RΦ(x)θ(log(f(x,θ)))f(x,θ)dx\partial_\theta V_0 = \int_{\mathbb{R}} \Phi(x) \partial_\theta(\log(f(x,\theta))) f(x,\theta) dx

or:

θV0=E(Φ(XT)θlog(f(XT,θ)))\partial_\theta V_0 = \mathbb{E}(\Phi(X_T) \partial_\theta \log(f(X_T,\theta)))

In case of n-th order sensitivities:

We observe that for a generic positive differentiable function f we can have:

g(x,θ)=logf(x,θ) g(x,\theta) = \log{f(x,\theta)}

or:

f(x,θ)=eg(x,θ) f(x,\theta) = e^{g(x,\theta)}

Then, according to Faa di Bruno's formula:

θneg(x,θ)=eg(x,θ)Bn({θig(x,θ)}i=1:n)\partial^{n}_{\theta} e^{g(x,\theta)} = e^{g(x,\theta)} B_n(\{\partial^{i}_{\theta} g(x,\theta)\}_{i = 1 : n})

Where BnB_n is the complete exponential Bell polynomial of n-th order.

B0=1B_0 = 1 B1(x1)=x1B_1(x_1) = x_1 B2(x1,x2)=x12+x2B_2(x_1,x_2) = x_1^2 + x_2 B3(x1,x2,x3)=x13+3x1x2+x3B_3(x_1,x_2,x_3) = x_1^3 + 3x_1 x_2 + x_3 B4(x1,x2,x3,x4)=x14+6x12x2+4x1x3+3x22+x4B_4(x_1,x_2,x_3,x_4) = x_1^4 + 6 x_1^2 x_2 + 4 x_1 x_3 + 3 x_2^2 + x_4 B5(x1,x2,x3,x4,x5)=x15+10x2x13+15x22x1+10x3x12+10x3x2+5x4x1+x5B_5(x_1,x_2,x_3,x_4,x_5) = x_1^5 + 10 x_2 x_1^3 + 15 x_2^2 x_1 + 10 x_3 x_1^2 + 10 x_3 x_2 + 5 x_4 x_1 + x_5 B6(x1,x2,x3,x4,x5,x6)=x16+15x2x14+20x3x13+45x22x12+15x23+60x3x2x1+15x4x12+10x32+15x4x2+6x5x1+x6B_6(x_1,x_2,x_3,x_4,x_5,x_6) = x_1^6 + 15 x_2 x_1^4 + 20 x_3 x_1^3 + 45 x_2^2 x_1^2 + 15 x_2^3 + 60 x_3 x_2 x_1 + 15 x_4 x_1^2 + 10 x_3^2 + 15 x_4 x_2 + 6 x_5 x_1 + x_6

Hence:

θnf(x,θ)=f(x,θ)Bn({θilogf(x,θ)}i=1:n)\partial^{n}_{\theta} f(x,\theta) = f(x,\theta) B_n(\{\partial^{i}_{\theta} \log{f(x,\theta)}\}_{i = 1 : n})

By applying this to the original problem:

θnV0=θnRΦ(x)f(x,θ)dx=RΦ(x)θnf(x,θ)dx\partial^{n}_{\theta} V_0=\partial^{n}_{\theta} \int_{\mathbb{R}} \Phi(x) f(x,\theta) dx = \int_{\mathbb{R}} \Phi(x) \partial^{n}_{\theta} f(x,\theta) dx

By applying the previous result:

θnV0=RΦ(x)f(x,θ)Bn({θilogf(x,θ)}i=1:n)dx\partial^{n}_{\theta} V_0= \int_{\mathbb{R}} \Phi(x) f(x,\theta) B_n(\{\partial^{i}_{\theta} \log{f(x,\theta)}\}_{i = 1 : n}) dx

or, in terms of expectation:

θnV0=E(Φ(XT)Bn({θilogf(XT,θ)}i=1:n))\partial^{n}_{\theta} V_0 = \mathbb{E}(\Phi(X_T) B_n(\{\partial^{i}_{\theta} \log{f(X_T,\theta)}\}_{i = 1 : n}))

Likelihood Ratio Method for Black and Scholes

In case of trivial models the density is known in analytic form, otherwise one need to compute it numerically from the characteristic function. In case of the Black and Scholes Model, and a European Option we have the following:

Xt=log(S0)+(rdσ22)t+σWtX_t=\log(S_0)+(r-d-\dfrac{\sigma^2}{2}) t + \sigma W_t log(f(x,S0,r,d,σ,T))=12((x(log(S0)+(rdσ22)T)σT)2+log(2π))log(σT)\log(f(x,S_0,r,d,\sigma,T)) = -\dfrac{1}{2}((\dfrac{x-(\log(S_0)+(r-d-\dfrac{\sigma^2}{2}) T)}{\sigma \sqrt{T}})^2 + \log(2 \pi)) - \log(\sigma\sqrt{T})

From this we can compute the various partial derivatives:

S0log(f(x,S0,r,d,σ,T))=xlog(S0)(rdσ22)Tσ2TS0 \partial_{S_0} \log(f(x,S_0,r,d,\sigma,T)) = \frac{x - \log\left( S_0 \right) - \left(r - d - \frac{\sigma^{2}}{2} \right) T}{\sigma^{2} T S_0} rlog(f(x,S0,r,d,σ,T))=xlog(S0)T(rdσ22)σ2 \partial_{r} \log(f(x,S_0,r,d,\sigma,T)) = \frac{ x - \log\left( S_0 \right) - T \left( r - d - \frac{\sigma^{2}}{2} \right) }{\sigma^{2}} dlog(f(x,S0,r,d,σ,T))=rlog(f(x,S0,r,d,σ,T)) \partial_{d} \log(f(x,S_0,r,d,\sigma,T)) = - \partial_{r} \log(f(x,S_0,r,d,\sigma,T)) σlog(f(x,S0,r,d,σ,T))=(xlog(S0)T(rdσ22))(TTxlog(S0)T(rdσ22)σ2TT)Tσ+1σ \partial_{\sigma} \log(f(x,S_0,r,d,\sigma,T)) =\frac{ - \left( x - \log\left( S_0 \right) - T \left( r - d - \frac{\sigma^{2}}{2} \right) \right) \left( \frac{T}{\sqrt{T}} - \frac{x - \log\left( S_0 \right) - T \left( r - d - \frac{\sigma^{2}}{2} \right)}{\sigma^{2} T} \sqrt{T} \right)}{\sqrt{T} \sigma} + \frac{-1}{\sigma} Tlog(f(x,S0,r,d,σ,T))=(xlog(S0)T(rdσ22))(dr+σ22Tσ+xlog(S0)T(rdσ22)σ2Tσ2T)Tσ+12T \partial_{T} \log(f(x,S_0,r,d,\sigma,T)) =\frac{ - \left( x - \log\left( S_0 \right) - T \left( r - d - \frac{\sigma^{2}}{2} \right) \right) \left( \frac{d - r + \frac{\sigma^{2}}{2}}{\sqrt{T} \sigma} + \frac{ - \frac{x - \log\left( S_0 \right) - T \left( r - d - \frac{\sigma^{2}}{2} \right)}{\sigma^{2} T} \sigma}{2 \sqrt{T}} \right)}{\sqrt{T} \sigma} + \frac{-1}{2 T}

Hence, a delta for a generic european option can be computed as the following expectation:

Δ=S0V0=E(Φ(XT)XTlog(S0)(rdσ22)Tσ2TS0)\Delta = \partial_{S_0} V_0 = \mathbb{E}(\Phi(X_T) \frac{X_T - \log\left( S_0 \right) - \left(r - d - \frac{\sigma^{2}}{2} \right) T}{\sigma^{2} T S_0} )

or, in terms of WTW_T:

Δ=S0V0=E(Φ(log(S0)+(rdσ22)T+σWT)WTσTS0)\Delta = \partial_{S_0} V_0 = \mathbb{E}(\Phi(\log(S_0)+(r-d-\dfrac{\sigma^2}{2}) T + \sigma W_T) \frac{W_T}{\sigma T S_0} )

Let's assume now that Φ\Phi is a forward i.e.:

Φ(x)=ex\Phi(x)=e^x

Since Δ=e(rd)T\Delta = e^{(r-d)T}:

E(eσ22T+σWTWT)=σT\mathbb{E}(e^{-\frac{\sigma^2}{2} T + \sigma W_T}\,W_T) = \sigma T

Spectral Theorem for Black and Scholes

Let's observe something, log(f(x,θ))\log(f(x,\theta)) is a second order polymial in xx:

logf(XT,θ)=i=02bi(θ)XTi=b0(θ)+b1(θ)XT+b2(θ)XT2\log{f(X_T,\theta)}= \sum_{i=0}^2 b_i(\theta) X_T^i = b_0(\theta) + b_1(\theta)\,X_T + b_2(\theta)\,X_T^2

Then all of the partial derivatives will be second order polynomials as well:

θilogf(XT,θ)=θib0(θ)+θib1(θ)XT+θib2(θ)XT2\partial^{i}_{\theta} \log{f(X_T,\theta)}= \partial^{i}_{\theta}b_0(\theta) + \partial^{i}_{\theta}b_1(\theta)\,X_T + \partial^{i}_{\theta}b_2(\theta)\,X_T^2

And the Bell exponential polymial will be a polynomial of degree 2n2 n in terms of XTX_T:

Bn({θilogf(XT,θ)}i=1:n)=i=02nai(θ,n)XTiB_n(\{\partial^{i}_{\theta} \log{f(X_T,\theta)}\}_{i = 1 : n}) = \sum_{i=0}^{2 n} a_i(\theta,n) X_T^i

And finally:

θnV0=a0(θ,n)V0+i=12nai(θ,n)E(Φ(XT)XTi)\partial^{n}_{\theta} V_0 = a_0(\theta,n) V_0 + \sum_{i=1}^{2 n} a_i(\theta,n) \mathbb{E}(\Phi(X_T) X_T^i)

To be noticed that the various coefficients ai(θ,n)a_i(\theta,n) do not depend on the payoff, hence with 2n+12n + 1 prices we are able to compute all of the partial derivatives with respect to any parameter up to order nn.

In case b2(θ)b_2(\theta) doesn't depend θ\theta then the corresponding nn order sensitivity can be expressed as a linear combination of the prices of n+1n + 1 contracts.

Application for sixth order derivative

Let's assume θ=r\theta = r, from the Spectral Theorem: 6Vθ6=E((15T3+45WT2T215WT4T+WT6)Φ(log(S0)+WTσ+T(d+r12σ2))σ6) \frac{\partial^{6} V}{\partial\theta^{6}} = \mathbb{E}\left( \frac{\left( - 15 T^{3} + 45 W_{T}^{2} T^{2} - 15 W_{T}^{4} T + W_{T}^{6} \right) \Phi\left( \log\left( S_{0} \right) + W_{T} \sigma + T \left( - d + r - \frac{1}{2} \sigma^{2} \right) \right)}{\sigma^{6}} \right) Hence we need to price 4 contracts to get the sixth order sensitivitity. To be noticed that one of the contract to be priced is the option itself.

Conditional Expectation

Let's fix a positive number τ<T\tau < T and let's assume now that the underlying process is a Levy process.
Since:

V0=E(Φ(XT))=E(E(Φ(XT)Xτ))V_0=\mathbb{E}(\Phi(X_T))=\mathbb{E}(\mathbb{E}(\Phi(X_T)|X_{\tau})) θV0=E(Φ(XT))=θE(E(Φ(XT)Xτ))=E(θE(Φ(XT)Xτ))\partial_{\theta} V_0=\mathbb{E}(\Phi(X_T))=\partial_{\theta} \mathbb{E}(\mathbb{E}(\Phi(X_T)|X_{\tau}))=\mathbb{E}(\partial_{\theta} \mathbb{E}(\Phi(X_{T})|X_{\tau}))

Conditional Saltando Expectation

Let's assume τ\tau is a stopping time st τ<T\tau < T a.s., and let's assume now that the underlying process is a Levy process.
Since:

V0=E(Φ(XT))=E(E(Φ(XT)Xτ))V_0=\mathbb{E}(\Phi(X_T))=\mathbb{E}(\mathbb{E}(\Phi(X_T)|X_{\tau})) θV0=E(Φ(XT))=θE(E(Φ(XT)Xτ))=E(θE(Φ(XT)Xτ))\partial_{\theta} V_0=\mathbb{E}(\Phi(X_T))=\partial_{\theta} \mathbb{E}(\mathbb{E}(\Phi(X_T)|X_{\tau}))=\mathbb{E}(\partial_{\theta} \mathbb{E}(\Phi(X_{T})|X_{\tau}))

Furthemore, if we assume that XtX_t is a finite activity Levy process, a smart choice of the law of the stopping time can benefit the computation of the inner expectation. Indeed, if we take τ\tau as the stopping time corresponding to the last jump of the process, we have that:

XtXτ is a Ito process  X_t | X_{\tau} \text{ is a Ito process }

Why is it useful?
Let's assume XtX_t is a Kou process, then XtXτX_t | X_{\tau} is a Brownian motion with a modified drift, hence we can have an analytic formula for the inner expectation.

Vibrato Montecarlo Method

Let's fix a positive number τ<T\tau < T and let's assume now that the underlying process is a Levy process.
Since:

V0=E(Φ(XT))=E(E(Φ(XT)Xτ))=E(E(Φ(Xτ+(XTXτ))Xτ))V_0=\mathbb{E}(\Phi(X_T))=\mathbb{E}(\mathbb{E}(\Phi(X_T)|X_{\tau}))=\mathbb{E}(\mathbb{E}(\Phi(X_{\tau}+(X_{T}-X_{\tau}))|X_{\tau})) θV0=E(Φ(XT))=θE(E(Φ(XT)Xτ))=θE(E(Φ(Xτ+(XTXτ))Xτ))\partial_{\theta} V_0=\mathbb{E}(\Phi(X_T))=\partial_{\theta} \mathbb{E}(\mathbb{E}(\Phi(X_T)|X_{\tau}))=\partial_{\theta} \mathbb{E}(\mathbb{E}(\Phi(X_{\tau}+(X_{T}-X_{\tau}))|X_{\tau})) θV0=E(θE(Φ(Xτ+(XTXτ))Xτ))\partial_{\theta} V_0=\mathbb{E}(\partial_{\theta} \mathbb{E}(\Phi(X_{\tau}+(X_{T}-X_{\tau}))|X_{\tau}))

Now we apply the LRM method to the inner expectation, let's call YTτ=XTXτY_{T-\tau}= X_{T}-X_{\tau}, then we have:

θE(Φ(XT)Xτ)=E(Φ(XT)θlog(fXTXτ(XTXτ,θ))Xτ)\partial_{\theta} \mathbb{E}(\Phi(X_{T})|X_{\tau}) = \mathbb{E}(\Phi(X_{T})\partial_{\theta} \log(f_{X_T-X_{\tau}}(X_T - X_{\tau},\theta))|X_{\tau})

Hence

θV0=E(E(Φ(XT)θlog(fXTXτ(XTXτ,θ))Xτ))\partial_{\theta} V_0=\mathbb{E}(\mathbb{E}(\Phi(X_{T})\partial_{\theta} \log(f_{X_T-X_{\tau}}(X_T - X_{\tau},\theta))|X_{\tau}))

or for a generic order n:

θnV0=E(E(Φ(XT)Bn({θilogfXTXτ(XTXτ,θ)}i=1:n)))\partial^{n}_{\theta} V_0=\mathbb{E}(\mathbb{E}(\Phi(X_{T}) B_n(\{\partial^{i}_{\theta} \log{f_{X_T-X_{\tau}}(X_T - X_{\tau},\theta)}\}_{i = 1 : n})))

As the traditional LR method, this is hard to apply in case the transition density is unknown. This can be easily solved in case of Ito processes where we can approximate the increment as a sum of powers of normal random variables. In case of more general process like Levy, one needs to invert numerically the density from the characteristic function.

Vibrato Saltando Montecarlo

Since what we stated above applies also to a generic stopping time τ\tau, we investigate some smart choice of the law of τ\tau in order to exploit some property of the underlying process. Let's assume now that XtX_t is a Finite Activity Levy process and that τ\tau is the stopping time corresponding to the last jump of the underlying. We know already that XtXτX_t|X_{\tau} is a Ito process. On such process we are able to apply the standard LRM or VBM since we know the corresponding law of the increments (powers of gaussians).