Local Volatility Examples - Maple Help

Home : Support : Online Help : Mathematics : Finance : Financial Instruments : Local Volatility Examples

Compute Local Volatility and Implied Volatility Using the Finance Package

Fitting Implied Volatility Surface

 > $\mathrm{restart}:$
 > $\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathrm{with}\left(\mathrm{LinearAlgebra}\right):$

First let us import prices of  S&P 500 call options available on October 27, 2006.

 > $\mathrm{Data}:=\mathrm{ImportMatrix}\left(\mathrm{FileTools}:-\mathrm{JoinPath}\left(\left[\mathrm{kernelopts}\left(\mathrm{datadir}\right),"finance","SP-500-CALLS.txt"\right]\right)\right)$

This data can be stored in a DataFrame.

 > $\mathrm{DF}≔\mathrm{DataFrame}\left(\mathrm{Data}\left[2..,..\right],\mathrm{columns}=\mathrm{Data}\left[1,..\right]\right)$

Extract data from this DataFrame.

 > $M,N{≔}_{}\mathrm{upperbound}\left(\mathrm{DF}\right)$
 ${M}{,}{N}{≔}{308}{,}{10}$ (1.1)

Value of the underlying, risk-free rate and dividend yield.

 > $\mathrm{S0}:=1377$
 ${\mathrm{S0}}{≔}{1377}$ (1.2)
 > $r:=0.0532$
 ${r}{≔}{0.05320}$ (1.3)
 > $d:=0.0182$
 ${d}{≔}{0.01820}$ (1.4)

Extract exercise dates and times for which data is available.

 > $\mathrm{ExerciseDates}≔\left[\mathrm{seq}\left(\mathrm{NthWeekday}\left(3,\mathrm{Friday},\mathrm{DF}\left[i,"Month"\right],\mathrm{DF}\left[i,"Year"\right]\right),i=1..M\right)\right]:$
 > $\mathrm{Times}:=\mathrm{map}\left(t\to \mathrm{YearFraction}\left("October 27, 2006",t\right),\mathrm{ExerciseDates}\right):$



Implied volatilities for options maturing in December 2006.

 >
 ${{\mathrm{Time}}}_{{1}}{≔}{0.13425}$ (1.5)

Extract a subset of the DataFrame corresponding to the observations in December 2006:

 >

Compute the implied volatility for these dates and plot the results:

 >
 > $\mathrm{dataplot}\left(\mathrm{L1}\left[..,1\right],\mathrm{L1}\left[..,2\right],\mathrm{gridlines},\mathrm{size}=\left[600,"golden"\right]\right)$

Implied volatilities for options maturing in December 2007.

 > ${\mathrm{Time}}_{2}≔\mathrm{YearFraction}\left("October 27, 2006",\mathrm{NthWeekday}\left(3,\mathrm{Friday},\mathrm{December},2007\right)\right)$
 ${{\mathrm{Time}}}_{{2}}{≔}{1.15068}$ (1.6)

Extract a subset of the DataFrame corresponding to the observations in December 2007:

 >

Compute the implied volatility for these dates and plot the results:

 >
 > $\mathrm{dataplot}\left(\mathrm{L2}\left[..,1\right],\mathrm{L2}\left[..,2\right],\mathrm{gridlines},\mathrm{size}=\left[600,"golden"\right]\right)$

We will use the following model for the volatility surface.

 > $\mathrm{Σ}:=\left(S,T,K\right)→{\mathrm{α}}_{1}+{\mathrm{α}}_{2}\mathrm{ln}\left(\frac{K}{S}\right)+\frac{{\mathrm{α}}_{3}}{\sqrt{T}}+{\mathrm{α}}_{4}{\mathrm{ln}\left(\frac{K}{S}\right)}^{2}+\frac{{\mathrm{α}}_{5}\mathrm{ln}\left(\frac{K}{S}\right)}{\sqrt{T}}+\frac{{\mathrm{α}}_{6}{\mathrm{ln}\left(\frac{K}{S}\right)}^{2}}{\sqrt{T}}$
 ${\mathrm{Σ}}{≔}\left({S}{,}{T}{,}{K}\right){→}{{\mathrm{α}}}_{{1}}{+}{{\mathrm{α}}}_{{2}}{}{\mathrm{ln}}{}\left(\frac{{K}}{{S}}\right){+}\frac{{{\mathrm{α}}}_{{3}}}{\sqrt{{T}}}{+}{{\mathrm{α}}}_{{4}}{}{{\mathrm{ln}}{}\left(\frac{{K}}{{S}}\right)}^{{2}}{+}\frac{{{\mathrm{α}}}_{{5}}{}{\mathrm{ln}}{}\left(\frac{{K}}{{S}}\right)}{\sqrt{{T}}}{+}\frac{{{\mathrm{α}}}_{{6}}{}{{\mathrm{ln}}{}\left(\frac{{K}}{{S}}\right)}^{{2}}}{\sqrt{{T}}}$ (1.7)

We can compute the corresponding Black-Scholes price as a function of strike and maturity.

 > $C:=\mathrm{BlackScholesPrice}\left(\mathrm{S0},K,T,\mathrm{Σ}\left(\mathrm{S0},T,K\right),r,d\right)$
 ${C}{≔}{1377.00000}{}{{ⅇ}}^{{-}{0.01820}{}{T}}{}\left({0.50000}{+}{0.50000}{}{\mathrm{erf}}{}\left(\frac{{0.70711}{}\left({\mathrm{ln}}{}\left(\frac{{1377.00000}}{{K}}\right){+}{0.03500}{}{T}{+}{0.50000}{}{\left({{\mathrm{α}}}_{{1}}{+}{{\mathrm{α}}}_{{2}}{}{\mathrm{ln}}{}\left({0.00073}{}{K}\right){+}\frac{{{\mathrm{α}}}_{{3}}}{\sqrt{{T}}}{+}{{\mathrm{α}}}_{{4}}{}{{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}^{{2}}{+}\frac{{{\mathrm{α}}}_{{5}}{}{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}{\sqrt{{T}}}{+}\frac{{{\mathrm{α}}}_{{6}}{}{{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}^{{2}}}{\sqrt{{T}}}\right)}^{{2}}{}{T}\right)}{\left({{\mathrm{α}}}_{{1}}{+}{{\mathrm{α}}}_{{2}}{}{\mathrm{ln}}{}\left({0.00073}{}{K}\right){+}\frac{{{\mathrm{α}}}_{{3}}}{\sqrt{{T}}}{+}{{\mathrm{α}}}_{{4}}{}{{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}^{{2}}{+}\frac{{{\mathrm{α}}}_{{5}}{}{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}{\sqrt{{T}}}{+}\frac{{{\mathrm{α}}}_{{6}}{}{{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}^{{2}}}{\sqrt{{T}}}\right){}\sqrt{{T}}}\right)\right){-}{1.00000}{}{{ⅇ}}^{{-}{0.05320}{}{T}}{}{K}{}\left({0.50000}{+}{0.50000}{}{\mathrm{erf}}{}\left(\frac{{0.70711}{}\left({\mathrm{ln}}{}\left(\frac{{1377.00000}}{{K}}\right){+}{0.03500}{}{T}{+}{0.50000}{}{\left({{\mathrm{α}}}_{{1}}{+}{{\mathrm{α}}}_{{2}}{}{\mathrm{ln}}{}\left({0.00073}{}{K}\right){+}\frac{{{\mathrm{α}}}_{{3}}}{\sqrt{{T}}}{+}{{\mathrm{α}}}_{{4}}{}{{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}^{{2}}{+}\frac{{{\mathrm{α}}}_{{5}}{}{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}{\sqrt{{T}}}{+}\frac{{{\mathrm{α}}}_{{6}}{}{{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}^{{2}}}{\sqrt{{T}}}\right)}^{{2}}{}{T}\right)}{\left({{\mathrm{α}}}_{{1}}{+}{{\mathrm{α}}}_{{2}}{}{\mathrm{ln}}{}\left({0.00073}{}{K}\right){+}\frac{{{\mathrm{α}}}_{{3}}}{\sqrt{{T}}}{+}{{\mathrm{α}}}_{{4}}{}{{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}^{{2}}{+}\frac{{{\mathrm{α}}}_{{5}}{}{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}{\sqrt{{T}}}{+}\frac{{{\mathrm{α}}}_{{6}}{}{{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}^{{2}}}{\sqrt{{T}}}\right){}\sqrt{{T}}}{-}{0.70711}{}\left({{\mathrm{α}}}_{{1}}{+}{{\mathrm{α}}}_{{2}}{}{\mathrm{ln}}{}\left({0.00073}{}{K}\right){+}\frac{{{\mathrm{α}}}_{{3}}}{\sqrt{{T}}}{+}{{\mathrm{α}}}_{{4}}{}{{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}^{{2}}{+}\frac{{{\mathrm{α}}}_{{5}}{}{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}{\sqrt{{T}}}{+}\frac{{{\mathrm{α}}}_{{6}}{}{{\mathrm{ln}}{}\left({0.00073}{}{K}\right)}^{{2}}}{\sqrt{{T}}}\right){}\sqrt{{T}}\right)\right)$ (1.8)

We can use non-linear fitting routines from the statistics data to find the values of that best fit our data. Construct a matrix of parameters and a vector of the corresponding value of the objective function.

 > $B:=⟨⟨\mathrm{Times}⟩|\mathrm{convert}\left(\mathrm{DF}\left["Strike"\right],\mathrm{Matrix}\right)⟩$
 > $V≔\mathrm{convert}\left(\mathrm{DF}\left["Ask"\right],\mathrm{Vector}\left[\mathrm{column}\right]\right)$
 >

Here is the corresponding implied volatility function.

 > $\mathrm{F1}:=\genfrac{}{}{0}{}{\mathrm{Σ}\left(\mathrm{S0},T,K\right)}{\phantom{\mathrm{α}=\mathrm{β1}}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}|\phantom{\rule[-0.0ex]{0.1em}{0.0ex}}\genfrac{}{}{0}{}{\phantom{\mathrm{Σ}\left(\mathrm{S0},T,K\right)}}{\mathrm{α}=\mathrm{β1}}$
 ${\mathrm{F1}}{≔}{0.14393}{+}{0.12599}{}{\mathrm{ln}}{}\left(\frac{{1}}{{1377}}{}{K}\right){-}\frac{{0.01069}}{\sqrt{{T}}}{-}{0.03301}{}{{\mathrm{ln}}{}\left(\frac{{1}}{{1377}}{}{K}\right)}^{{2}}{-}\frac{{0.30394}{}{\mathrm{ln}}{}\left(\frac{{1}}{{1377}}{}{K}\right)}{\sqrt{{T}}}{+}\frac{{0.40480}{}{{\mathrm{ln}}{}\left(\frac{{1}}{{1377}}{}{K}\right)}^{{2}}}{\sqrt{{T}}}$ (1.9)
 > $\mathrm{plot3d}\left(\mathrm{F1},T=0..2.5,K=600..1500\right)$
 >

Here is another way to estimate these parameters.

 > $U:=\mathrm{Vector}\left(1..M\right)$
 >
 > $\mathrm{β2}≔\mathrm{NonlinearFit}\left(\mathrm{Σ}\left(\mathrm{S0},T,K\right),B,U,\left[T,K\right],\mathrm{parameternames}=\left[{\mathrm{α}}_{1},{\mathrm{α}}_{2},{\mathrm{α}}_{3},{\mathrm{α}}_{4},{\mathrm{α}}_{5},{\mathrm{α}}_{6}\right],\mathrm{output}=\mathrm{parametervector}\right)$

Here is the corresponding implied volatility function.

 > $\mathrm{F2}:=\genfrac{}{}{0}{}{\mathrm{Σ}\left(\mathrm{S0},T,K\right)}{\phantom{\mathrm{α}=\mathrm{β2}}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}|\phantom{\rule[-0.0ex]{0.1em}{0.0ex}}\genfrac{}{}{0}{}{\phantom{\mathrm{Σ}\left(\mathrm{S0},T,K\right)}}{\mathrm{α}=\mathrm{β2}}$
 ${\mathrm{F2}}{≔}{0.13011}{+}{0.17037}{}{\mathrm{ln}}{}\left(\frac{{1}}{{1377}}{}{K}\right){+}\frac{{0.00115}}{\sqrt{{T}}}{-}{0.26597}{}{{\mathrm{ln}}{}\left(\frac{{1}}{{1377}}{}{K}\right)}^{{2}}{-}\frac{{0.36133}{}{\mathrm{ln}}{}\left(\frac{{1}}{{1377}}{}{K}\right)}{\sqrt{{T}}}{+}\frac{{0.28070}{}{{\mathrm{ln}}{}\left(\frac{{1}}{{1377}}{}{K}\right)}^{{2}}}{\sqrt{{T}}}$ (1.10)
 > $\mathrm{plot3d}\left(\mathrm{F2},T=0..2.5,K=600..1500\right)$
 >

We can compare both fits with the actual implied volatilities.

 > $P≔\mathrm{dataplot}\left(\mathrm{L1}\left[..,1\right],\mathrm{L1}\left[..,2\right]\right):$
 > $\mathrm{P1}:=\mathrm{plot}\left(\genfrac{}{}{0}{}{\mathrm{F1}}{\phantom{T={\mathrm{Time}}_{1}}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}|\phantom{\rule[-0.0ex]{0.1em}{0.0ex}}\genfrac{}{}{0}{}{\phantom{\mathrm{F1}}}{T={\mathrm{Time}}_{1}},K=800..1500,\mathrm{thickness}=3,\mathrm{color}=\mathrm{red}\right):$
 > $\mathrm{P2}:=\mathrm{plot}\left(\genfrac{}{}{0}{}{\mathrm{F2}}{\phantom{T={\mathrm{Time}}_{1}}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}|\phantom{\rule[-0.0ex]{0.1em}{0.0ex}}\genfrac{}{}{0}{}{\phantom{\mathrm{F2}}}{T={\mathrm{Time}}_{1}},K=800..1500,\mathrm{thickness}=3,\mathrm{color}=\mathrm{green}\right):$
 > $\mathrm{display}\left(P,\mathrm{P1},\mathrm{P2},\mathrm{axes}=\mathrm{boxed},\mathrm{gridlines},\mathrm{size}=\left[600,"golden"\right]\right)$
 > $P≔\mathrm{dataplot}\left(\mathrm{L2}\left[..,1\right],\mathrm{L2}\left[..,2\right]\right):$
 > $\mathrm{P1}:=\mathrm{plot}\left(\genfrac{}{}{0}{}{\mathrm{F1}}{\phantom{T={\mathrm{Time}}_{2}}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}|\phantom{\rule[-0.0ex]{0.1em}{0.0ex}}\genfrac{}{}{0}{}{\phantom{\mathrm{F1}}}{T={\mathrm{Time}}_{2}},K=1000..1500,\mathrm{thickness}=3,\mathrm{color}=\mathrm{red}\right):$
 > $\mathrm{P2}:=\mathrm{plot}\left(\genfrac{}{}{0}{}{\mathrm{F2}}{\phantom{T={\mathrm{Time}}_{2}}}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}|\phantom{\rule[-0.0ex]{0.1em}{0.0ex}}\genfrac{}{}{0}{}{\phantom{\mathrm{F2}}}{T={\mathrm{Time}}_{2}},K=1000..1500,\mathrm{thickness}=3,\mathrm{color}=\mathrm{green}\right):$
 > $\mathrm{display}\left(P,\mathrm{P1},\mathrm{P2},\mathrm{gridlines},\mathrm{axes}=\mathrm{boxed},\mathrm{size}=\left[600,"golden"\right]\right)$

Modeling with Local Volatility

We will consider the same model for the local volatility except that in this case we will use parameters that were fit to some market data.

 > $\mathrm{restart}:$$\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathrm{with}\left(\mathrm{Finance}\right):$
 > $\mathrm{Σ}:={\mathrm{α}}_{1}+{\mathrm{α}}_{2}\mathrm{ln}\left(\frac{K}{\mathrm{S0}}\right)+\frac{{\mathrm{α}}_{3}\cdot 1}{\sqrt{T}}+{\mathrm{α}}_{4}{\mathrm{ln}\left(\frac{K}{\mathrm{S0}}\right)}^{2}+\frac{{\mathrm{α}}_{5}\mathrm{ln}\left(\frac{K}{\mathrm{S0}}\right)}{\sqrt{T}}+\frac{{\mathrm{α}}_{6}{\mathrm{ln}\left(\frac{K}{\mathrm{S0}}\right)}^{2}}{\sqrt{T}}$
 ${\mathrm{Σ}}{≔}{{\mathrm{α}}}_{{1}}{+}{{\mathrm{α}}}_{{2}}{}{\mathrm{ln}}{}\left(\frac{{K}}{{\mathrm{S0}}}\right){+}\frac{{{\mathrm{α}}}_{{3}}}{\sqrt{{T}}}{+}{{\mathrm{α}}}_{{4}}{}{{\mathrm{ln}}{}\left(\frac{{K}}{{\mathrm{S0}}}\right)}^{{2}}{+}\frac{{{\mathrm{α}}}_{{5}}{}{\mathrm{ln}}{}\left(\frac{{K}}{{\mathrm{S0}}}\right)}{\sqrt{{T}}}{+}\frac{{{\mathrm{α}}}_{{6}}{}{{\mathrm{ln}}{}\left(\frac{{K}}{{\mathrm{S0}}}\right)}^{{2}}}{\sqrt{{T}}}$ (2.1)
 > ${\mathrm{α}}_{1}≔0.1581:$${\mathrm{α}}_{2}:=-0.2777:$${\mathrm{α}}_{3}:=-0.0050:$${\mathrm{α}}_{4}:=-0.5011:$${\mathrm{α}}_{5}≔0.1103:$${\mathrm{α}}_{6}:=0.5909:$
 > $\mathrm{S0}:=100$
 ${\mathrm{S0}}{≔}{100}$ (2.2)
 > $\mathrm{Σ}$
 ${0.15810}{-}{0.27770}{}{\mathrm{ln}}{}\left(\frac{{1}}{{100}}{}{K}\right){-}\frac{{0.00500}}{\sqrt{{T}}}{-}{0.50110}{}{{\mathrm{ln}}{}\left(\frac{{1}}{{100}}{}{K}\right)}^{{2}}{+}\frac{{0.11030}{}{\mathrm{ln}}{}\left(\frac{{1}}{{100}}{}{K}\right)}{\sqrt{{T}}}{+}\frac{{0.59090}{}{{\mathrm{ln}}{}\left(\frac{{1}}{{100}}{}{K}\right)}^{{2}}}{\sqrt{{T}}}$ (2.3)
 > $\mathrm{plot3d}\left(\mathrm{Σ},K=50..150,T=0.1..2\right)$

Consider two functions. The first one returns the Black-Scholes price of a European call option for our model. The second one returns the Black-Scholes price of a European put option for our model. We will assume that these functions are given two us (e.g. obtained by interpolating the market data) and will try to determine the corresponding local volatility term structure.

 > $C:=\mathrm{BlackScholesPrice}\left(\mathrm{S0},K,T,\mathrm{Σ},0.05,0.01,'\mathrm{call}'\right):$
 > $P:=\mathrm{BlackScholesPrice}\left(\mathrm{S0},K,T,\mathrm{Σ},0.05,0.01,'\mathrm{put}'\right):$

Construct the corresponding local volatility surface.

 > $V:=\mathrm{LocalVolatilitySurface}\left(0.05,0.01,C,K,T\right):$
 > $\mathrm{S1}:=⟨\mathrm{seq}\left(i,i=50..200\right)⟩$
 > $\mathrm{T1}:=⟨\mathrm{seq}\left(0.02i,i=1..50\right)⟩$
 > $V:=\mathrm{LocalVolatility}\left(C,\mathrm{S1},\mathrm{T1},0.05,0.01,T,K\right)$
 > $\mathrm{LV}:=\mathrm{LocalVolatility}\left(C,S,T,0.05,0.01,T,K\right):$
 >
 >
 > ${\mathrm{plots}}_{\mathrm{display}}\left(\mathrm{P1},\mathrm{P2}\right)$

We can construct the corresponding local volatility surface and implied volatility surface.

 > $\mathrm{LVS}:=\mathrm{LocalVolatilitySurface}\left(\mathrm{T1},\mathrm{S1},V\right):$
 > $\mathrm{IVS}:=\mathrm{ImpliedVolatilitySurface}\left(\mathrm{Σ},T,K\right):$

We can now construct a Black-Scholes process which has the volatility structure we just obtained.

 > $X:=\mathrm{BlackScholesProcess}\left(100,\mathrm{LVS},0.05,0.01\right)$
 ${X}{≔}{\mathrm{_X}}$ (2.4)
 >
 > $\mathrm{P1}:=\mathrm{subs}\left(K=\mathrm{S0}x,\frac{1P}{\mathrm{S0}}\right):$
 > $\mathrm{C1}:=\mathrm{subs}\left(K=\mathrm{S0}x,\frac{1C}{\mathrm{S0}}\right):$
 > $T:='T'$
 ${T}{≔}{T}$ (2.5)

As an alternative, we can use the implied volatility surface to construct an implied trinomial tree.

 > $\mathrm{TT}:=\mathrm{ImpliedTrinomialTree}\left(100,0.05,0.01,\mathrm{IVS},1,100\right):$
 > $\mathrm{GetLocalVolatility}\left(\mathrm{TT},99,99,0.05\right)$
 ${0.15319}$ (2.6)
 > $\mathrm{IVS}\left(1.0,100\right)$
 ${0.15310}$ (2.7)

Compute some option prices. We can use Monte-Carlo simulation to price European-style options and lattice methods to price American-style options.

 > $\mathrm{ExpectedValue}\left(\mathrm{max}\left(X\left(1\right)-100,0\right),\mathrm{timesteps}=100,\mathrm{replications}={10}^{4}\right)$
 $\left[{\mathrm{value}}{=}{8.55963}{,}{\mathrm{standarderror}}{=}{0.09592}\right]$ (2.8)
 > $E:=\mathrm{EuropeanOption}\left(t→\mathrm{max}\left(t-100,0\right),1.0\right)$
 ${E}{≔}{\mathbf{module}}\left({}\right)\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{...}\phantom{\rule[-0.0ex]{0.5em}{0.0ex}}{\mathbf{end module}}$ (2.9)
 > $\mathrm{LatticePrice}\left(E,\mathrm{TT},0.0\right)$
 ${8.47775}$ (2.10)

Here is an example of an Asian-type option with European exercise.

 > $\mathrm{ExpectedValue}\left(\mathrm{max}\left({{∫}}_{0}^{1}X\left(u\right)\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}{ⅆ}u-100,0\right),\mathrm{timesteps}=100,\mathrm{replications}={10}^{3}\right)$
 $\left[{\mathrm{value}}{=}{4.45120}{,}{\mathrm{standarderror}}{=}{0.18170}\right]$ (2.11)