Local Volatility Examples - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


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

Modeling with Local Volatility

Fitting Implied Volatility Surface

restart:

withLinearAlgebra:withFinance:withStatistics: withplots:interfacedisplayprecision=5:

 

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

Data:=ImportMatrixFileTools:-JoinPathkerneloptsdatadir,finance,SP-500-CALLS.txt

This data can be stored in a DataFrame.

DFDataFrameData2..,..,columns=Data1,..

 

Extract data from this DataFrame.

M,NupperboundDF

M,N308,10

(1.1)

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

S0:=1377

S01377

(1.2)

r:=0.0532

r0.05320

(1.3)

d:=0.0182

d0.01820

(1.4)

 

Extract exercise dates and times for which data is available.

ExerciseDatesseqNthWeekday3,Friday,DFi,Month,DFi,Year,i=1..M:

Times:=maptYearFractionOctober 27, 2006,t,ExerciseDates:

Implied volatilities for options maturing in December 2006.

TimeExample1YearFractionOctober 27, 2006,NthWeekday3,Friday, December,2006

TimeExample10.13425

(1.5)

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

Dec2006DFDFMonth =~ December and DFYear =~ 2006

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

L1Matrixseq  Dec2006i, Strike, ImpliedVolatility Dec2006i, Ask, S0, Dec2006i, Strike, TimeExample1, r, d  , i = 1 .. NumRowsDec2006,datatype=float8

dataplotL1..,1,L1..,2,gridlines,size=600,golden

 

Implied volatilities for options maturing in December 2007.

TimeExample2YearFractionOctober 27, 2006,NthWeekday3,Friday,December,2007

TimeExample21.15068

(1.6)

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

Dec2007DFDFMonth =~ December and DFYear =~ 2007

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

L2Matrixseq  Dec2007i, Strike, ImpliedVolatility Dec2007i, Ask, S0, Dec2007i, Strike, TimeExample2, r, d  , i = 1 .. NumRowsDec2007,datatype=float8

dataplotL2..,1,L2..,2,gridlines,size=600,golden

 

We will use the following model for the volatility surface.

Σ:=S,T,K→α1+α2lnKS+α3T+α4lnKS2+α5lnKST+α6lnKS2T

ΣS,T,Kα1+α2lnKS+α3T+α4lnKS2+α5lnKST+α6lnKS2T

(1.7)

 

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

C:=BlackScholesPriceS0,K,T,ΣS0,T,K,r,d

C1377.00000ⅇ0.01820T0.50000+0.50000erf0.70711ln1377.00000K+0.03500T+0.50000α1+α2ln0.00073K+α3T+α4ln0.00073K2+α5ln0.00073KT+α6ln0.00073K2T2Tα1+α2ln0.00073K+α3T+α4ln0.00073K2+α5ln0.00073KT+α6ln0.00073K2TT1.00000ⅇ0.05320TK0.50000+0.50000erf0.70711ln1377.00000K+0.03500T+0.50000α1+α2ln0.00073K+α3T+α4ln0.00073K2+α5ln0.00073KT+α6ln0.00073K2T2Tα1+α2ln0.00073K+α3T+α4ln0.00073K2+α5ln0.00073KT+α6ln0.00073K2TT0.70711α1+α2ln0.00073K+α3T+α4ln0.00073K2+α5ln0.00073KT+α6ln0.00073K2TT

(1.8)

 

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

B:=Times|convertDFStrike,Matrix

VconvertDFAsk,Vectorcolumn

β1NonlinearFitC,B, V,T,K,parameternames=α1,α2,α3,α4,α5,α6,output=parametervector

β1

(1.9)

 

Here is the corresponding implied volatility function.

F1:=ΣS0,T,Kα=β1|ΣS0,T,Kα=β1

F10.14393+0.12599lnK13770.01069T0.03301lnK137720.30394lnK1377T+0.40480lnK13772T

(1.10)

plot3dF1,T=0..2.5,K=600..1500,view=0..2.6

animateplot,F1,K=600..1500,thickness=3,T=0.1..3,axes=boxed, gridlines,size=600,golden

 

Here is another way to estimate these parameters.

U:=Vector1..M

for i to M doUi:=ImpliedVolatilityVi,S0,Bi,2,Bi,1,r,dend do:

β2NonlinearFitΣS0,T,K,B,U,T,K,parameternames=α1,α2,α3,α4,α5,α6,output=parametervector

β2

(1.11)

 

Here is the corresponding implied volatility function.

F2:=ΣS0,T,Kα=β2|ΣS0,T,Kα=β2

F20.13011+0.17037lnK1377+0.00115T0.26597lnK137720.36133lnK1377T+0.28070lnK13772T

(1.12)

plot3dF2,T=0..2.5,K=600..1500,view=0..2

animateplot,F2,K=600..1500,thickness=3,T=0.1..3, gridlines, axes = boxed,size=600,golden

 

We can compare both fits with the actual implied volatilities.

PdataplotL1..,1,L1..,2:

P1:=plotF1T=TimeExample1|F1T=TimeExample1,K=800..1500,thickness=3,color=red:

P2:=plotF2T=TimeExample1|F2T=TimeExample1,K=800..1500,thickness=3,color=green:

displayP,P1,P2,axes=boxed,gridlines,size=600,golden

PdataplotL2..,1,L2..,2:

P1:=plotF1T=TimeExample2|F1T=TimeExample2,K=1000..1500,thickness=3,color=red:

P2:=plotF2T=TimeExample2|F2T=TimeExample2,K=1000..1500,thickness=3,color=green:

displayP,P1,P2,gridlines,axes=boxed,size=600,golden

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.

restart

withFinance:

Σ:=α1+α2lnKS0+α31T+α4lnKS02+α5lnKS0T+α6lnKS02T

Σα1+α2lnKS0+α3T+α4lnKS02+α5lnKS0T+α6lnKS02T

(2.1)

α10.1581:α2:=0.2777:α3:=0.0050:α4:=0.5011:α50.1103:α6:=0.5909:

S0:=100

S0100

(2.2)

Σ

0.15810.2777lnK1000.0050T0.5011lnK1002+0.1103lnK100T+0.5909lnK1002T

(2.3)

plot3dΣ,K=50..150,T=0.1..2

 

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:=BlackScholesPriceS0,K,T,Σ,0.05,0.01,'call':

P:=BlackScholesPriceS0,K,T,Σ,0.05,0.01,'put':

 

Construct the corresponding local volatility surface.

V:=LocalVolatilitySurface0.05,0.01,C,K,T:

S1:=seqi,i=50..200

T1:=seq0.02i,i=1..50

V:=LocalVolatilityC,S1,T1,0.05,0.01,T,K

LV:=LocalVolatilityC,S,T,0.05,0.01,T,K:

P1  plot3dLV,S=50..150,T=0.05..1, color = blue:

P2:=plot3dΣ,K=50..150,T=0.05..1, color = red:

plotsdisplayP1,P2,view=0..1.5

 

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

LVS:=LocalVolatilitySurfaceT1,S1,V:

IVS:=ImpliedVolatilitySurfaceΣ,T,K:

 

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

X:=BlackScholesProcess100,LVS,0.05,0.01

X_X0

(2.4)

PathPlotXt,t=0..1,timesteps=20,replications=20,thickness=3,color=red..yellow,axes= boxed, gridlines,size=600,golden

P1:=subsK=S0x,1PS0:

C1:=subsK=S0x,1CS0:

T:='T':

 

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

TT:=ImpliedTrinomialTree100,0.05,0.01,IVS,1,100:

GetLocalVolatilityTT,99,99,0.05

0.1531851114

(2.5)

IVS1.0,100

0.1531000000

(2.6)

 

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

ExpectedValuemaxX1100,0,timesteps=100,replications=104

value=8.562255135,standarderror=0.09642955646

(2.7)

E:=EuropeanOptiont→maxt100,0,1.0:

LatticePriceE,TT,0.0

8.477754630

(2.8)

 

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

ExpectedValuemax∫01Xuⅆu100,0,timesteps=100,replications=103

value=4.311947370,standarderror=0.1787554842

(2.9)