VBA coding application in fx option market, the mission is 1) to compare the implied volatility in market and the implied volatilities computed by Newton method while inputting different times of maturity, strike price, we find that there are big discrepancies when the moneyness is quite great or quite small, which means that there might be some arbitrage. 2) To build the model by using object structure in VBA ---- Class, which allows us to facilitate the coding and we use it to compute the delta when there are different time of maturity and strike price.
Pooja 9892124323 : Call Girl in Juhu Escorts Service Free Home Delivery
Β
Comparison market implied volatilities with implied volatilities computed by newton
1. Comparison market implied volatilities with implied volatilities
computed by Newtonβs analytical method.
This code is implemented by VBA to compare those difference between a real implied and a
calculated so that to find whether there is an arbitrage opportunity.
Market focus on Forex GBP/USD market, by price model will apply black-choles formula to
calculate the option price which is below:
π = π0 πβπ π π
π(π1) β πΎπβπ π π
π(π2)
Where:
π1 =
ln(
π0
πΎ
)+(π π+π πβ
π2
2
)π
πβπ
π2 = π1 β πβπ
π0 ππ π‘βπ ππ’πππππ‘ π πππ‘ πππ‘π
πΎ is the strike price
N(x) is the cumulative normal distribution function
ππ is domestic risk free simple interest rate
ππ is foreign risk free simple interest rate
T is the time to maturity (calculated according to the appropriate day count
convention)
π ππ π‘βπ πππππππ π£ππππ‘ππππ‘π¦ ππ π‘βπ πΉπ πππ‘π
Code below is to compute the implied volatilities by inputting the option price, time to
maturity, spot FX rate, risk free rate in British and US (assumed), strike FX rate
======================================================================
Sub forex()
Worksheets("GBPUSD").Select
Dim S As Integer
S = Sheets("GBPUSD").Cells(Rows.Count, "A").End(xlUp).Row
Dim rate As Range
Set rate = Range(Range("C2"), Range("C" & S))
'MsgBox s
Range("B" & S + 3).value = "mean"
Range("B" & S + 4).value = "std"
Range("c" & S + 3) = WorksheetFunction.Average(rate)
Range("c" & S + 4) = WorksheetFunction.StDev_S(rate)
Dim histstd() As Double
2. ReDim histstd(S - 3) As Double
Range("D1").value = "Date"
Range("E1").value = "HISTORIC STD"
Range("f1").value = "Historic volatility"
For i = 0 To S - 3
histstd(i) = WorksheetFunction.StDev_P(Range(Range("c" & S - 1 - i), Range("c" & S)))
Next i
MsgBox i
j = 1
For Each element In histstd
j = j + 1
'MsgBox " 12" & element
Range("D" & j).value = Range("a" & 265 - j).value
Range("E" & j).value = element
Range("f" & j).value = Range("e" & j).value * Sqr(360)
Next
End Sub
======================================================================
Function optionprice(ByVal spot As Double, strike As Double, maturity As Double, ByVal rf1 As
Double, ByVal rf2 As Double, vol As Double) As Double
Dim a, b As Double
a = WorksheetFunction.Ln(spot / strike) + (rf1 - rf2 + vol * vol * 0.5) * maturity
b = a - vol * Sqr(maturity)
optionprice = spot * Exp(-rf2 * maturity) * WorksheetFunction.NormSDist(Arg1:=a) - strike *
Exp(-rf1 * maturity) * WorksheetFunction.NormSDist(Arg1:=b)
End Function
======================================================================
Function ImpliedVolatility(ByVal spot As Double, strike As Double, maturity As Double, ByVal
rf1 As Double, ByVal rf2 As Double, ByVal OptionValue As Double)
Dim epsilon As Double, dVol As Double, vol_1 As Double
Dim i As Integer, maxIter As Integer, Value_1 As Double, vol_2 As Double
Dim Value_2 As Double, dx As Double
dVol = 1E-05
epsilon = 1E-05
maxIter = 1000
3. Do
Value_1 = optionprice(spot, strike, maturity, rf1, rf2, vol_1)
vol_2 = vol_1 - dVol
Value_2 = optionprice(spot, strike, maturity, rf1, rf2, vol_2)
dx = (Value_1 - Value_2) / dVol
If Abs(dx) < epsilon Or i = maxIter Then Exit Do
vol_1 = vol_1 + (OptionValue - Value_1) / dx
i = i + 1
Loop
ImpliedVolatility = vol_1
End Function
======================================================================
Sub forexoption()
Dim strike1(10) As Double
strike1(1) = 1.294
strike1(2) = 1.296
strike1(3) = 1.298
strike1(4) = 1.3
strike1(5) = 1.302
strike1(6) = 1.304
strike1(7) = 1.306
strike1(8) = 1.308
strike1(9) = 1.31
strike1(10) = 1.312
Dim strike2(10) As Double
strike2(1) = 1.288
strike2(2) = 1.291
strike2(3) = 1.294
strike2(4) = 1.297
strike2(5) = 1.3
strike2(6) = 1.303
strike2(7) = 1.306
strike2(8) = 1.309
strike2(9) = 1.312
strike2(10) = 1.315
Dim strike(10, 5) As Double
Dim impexchange(10, 5) As Double
For i1 = 1 To 10
For j1 = 1 To 5
Worksheets("raw data").Select
strike(i1, j1) = Cells(i1, j1)
impexchange(i1, j1) = Cells(i1 + 22, j1)
Next j1
4. Next i1
Dim maturity(7) As Double
maturity(1) = 1 / 52
maturity(2) = 1 / 26
maturity(3) = 1 / 12
maturity(4) = 1 / 6
maturity(5) = 1 / 4
maturity(6) = 1 / 2
maturity(7) = 1
Dim price1(10) As Double
price1(1) = 0.00992
price1(2) = 0.00846
price1(3) = 0.00706
price1(4) = 0.00577
price1(5) = 0.00453
price1(6) = 0.00366
price1(7) = 0.00286
price1(8) = 0.0021
price1(9) = 0.00169
price1(10) = 0.00128
Dim price2(10) As Double
price2(1) = 0.01625
price2(2) = 0.01364
price2(3) = 0.01147
price2(4) = 0.00938
price2(5) = 0.00743
price2(6) = 0.00581
price2(7) = 0.0045
price2(8) = 0.0034
price2(9) = 0.00253
price2(10) = 0.00195
Dim price(10, 5) As Double
For S = 1 To 10
For T = 1 To 5
Worksheets("raw data").Select
price(S, T) = Cells(11 + S, T)
Next T
Next S
Worksheets("GBPUSD").Select
5. Dim domesticrf, foreignrf As Double
domesticrf = 0.75 / 100
foreignrf = 1.54 / 100
spot = 1.2992
Dim impvol() As Double
ReDim impvol(10) As Double
For i2 = 1 To 7
a = 1 + (i2 - 1) * 13
Range("j" & a).value = "theotical option price"
Range("k" & a).value = "real price"
Range("l" & a).value = "implied volatility"
Range("I" & a).value = "strike price"
Range("M" & a).value = "implied volatility at exchange"
'Range("j14").Value = "theotical option price"
'Range("k14").Value = "real price"
'Range("l14").Value = "implied volatility"
Next i2
For i = 1 To 10
Range("k" & i + 1).value = price1(i)
Range("j" & i + 1).value = optionprice(spot, strike1(i), maturity(1), domesticrf, foreignrf,
impvol(1))
'Set to_value = Range("k" & i + 1)
impvol(i) = ImpliedVolatility(spot, strike1(i), maturity(1), rf1, rf2, price1(i))
're-calculate theoretical price by using the implied volatilities
Range("j" & i + 1).value = optionprice(spot, strike1(i), maturity(1), domesticrf, foreignrf,
impvol(i))
Range("l" & i + 1).value = impvol(i)
'maturity two weeks
Range("k" & i + 14).value = price1(i)
Range("j" & i + 14).value = optionprice(spot, strike2(i), maturity(2), domesticrf, foreignrf,
impvol(2))
'Set to_value = Range("k" & i + 1)
impvol(i) = ImpliedVolatility(spot, strike2(i), maturity(2), rf1, rf2, price2(i))
're-calculate theoretical price by using the implied volatilities
6. Range("j" & i + 14).value = optionprice(spot, strike2(i), maturity(2), domesticrf, foreignrf,
impvol(i))
Range("l" & i + 14).value = impvol(i)
Next i
'using for loop to calculate array of implied volatility, theoretical price with different maturity
Worksheets("GBPUSD").Select
For i3 = 3 To 7
For i4 = 1 To 10
b = 1 + (i3 - 1) * 13 + i4
Range("k" & b).value = price(i4, i3 - 2)
Range("j" & b).value = optionprice(spot, strike(i4, i3 - 2), maturity(i3), domesticrf,
foreignrf, impvol(1))
impvol(i4) = ImpliedVolatility(spot, strike(i4, i3 - 2), maturity(i3), rf1, rf2, price(i4, i3 - 2))
Range("j" & b).value = optionprice(spot, strike(i4, i3 - 2), maturity(i3), domesticrf,
foreignrf, impvol(i4))
Range("l" & b).value = impvol(i4)
Range("i" & b).value = strike(i4, i3 - 2)
Range("m" & b).value = impexchange(i4, i3 - 2)
Next i4
Next i3
End Sub
======================================================================
Sub plot_smile1()
Dim sh As Worksheet
Set sh = ActiveWorkbook.Worksheets("GBPUSD")
sh.ChartObjects.Delete
Dim xrng1 As Range
Dim yrng1 As Range
Range("L2:L11").Select
Set yrng1 = Range("L2:L11")
Range("M2:m11").Select
Set yrng2 = Range("m2:m11")
Range("K2:K11").Select
Set xrng1 = Range("i2:i11")
7. Dim Chart As Chart
Set Chart = sh.Shapes.AddChart.Chart
With Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
'Change to what your series should be called
.SeriesCollection(1).Name = "theoritical volatility smile at the maturity = one week"
.SeriesCollection(1).XValues = xrng1
.SeriesCollection(1).Values = yrng1
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Strike price"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Theoritical implied vol"
End With
With Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
'Change to what your series should be called
.SeriesCollection(2).Name = "realized volatility smile at the maturity = one week"
.SeriesCollection(2).XValues = xrng1
.SeriesCollection(2).Values = yrng2
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Strike price"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "realized implied vol"
End With
End Sub
Sub plot_smile2()
Dim sh As Worksheet
Set sh = ActiveWorkbook.Worksheets("GBPUSD")
Dim xrng2 As Range
Dim yrng3, yrng4 As Range
Range("L15:L24").Select
Set yrng3 = Range("L15:L24")
Range("M15:m24").Select
Set yrng4 = Range("m15:m24")
Range("K15:K24").Select
Set xrng2 = Range("i15:i24")
8. Dim Chart As Chart
Set Chart = sh.Shapes.AddChart.Chart
With Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
'Change to what your series should be called
.SeriesCollection(1).Name = "theoritical volatility smile at the maturity = one week"
.SeriesCollection(1).XValues = xrng2
.SeriesCollection(1).Values = yrng3
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Strike price"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Theoritical implied vol"
End With
With Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
'Change to what your series should be called
.SeriesCollection(2).Name = "realized volatility smile at the maturity = two week"
.SeriesCollection(2).XValues = xrng2
.SeriesCollection(2).Values = yrng4
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Strike price"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "realized implied vol"
End With
End Sub
Sub plot_smile4()
Dim sh As Worksheet
Set sh = ActiveWorkbook.Worksheets("GBPUSD")
Dim xrng2 As Range
Dim yrng3, yrng4 As Range
Range("L41:L50").Select
Set yrng3 = Range("L41:L50")
Range("M41:m50").Select
Set yrng4 = Range("m41:m50")
9. Range("K41:K50").Select
Set xrng2 = Range("i41:i50")
Dim Chart As Chart
Set Chart = sh.Shapes.AddChart.Chart
With Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
'Change to what your series should be called
.SeriesCollection(1).Name = "theoritical volatility smile at the maturity = one week"
.SeriesCollection(1).XValues = xrng2
.SeriesCollection(1).Values = yrng3
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Strike price"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Theoritical implied vol"
End With
With Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
'Change to what your series should be called
.SeriesCollection(2).Name = "realized volatility smile at the maturity = two week"
.SeriesCollection(2).XValues = xrng2
.SeriesCollection(2).Values = yrng4
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Strike price"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "realized implied vol"
End With
End Sub
Sub plot_smile5()
Dim sh As Worksheet
Set sh = ActiveWorkbook.Worksheets("GBPUSD")
Dim xrng2 As Range
Dim yrng3, yrng4 As Range
Range("L54:L63").Select
Set yrng3 = Range("L54:L63")
Range("M54:m63").Select
10. Set yrng4 = Range("m54:m63")
Range("K54:K63").Select
Set xrng2 = Range("i54:i63")
Dim Chart As Chart
Set Chart = sh.Shapes.AddChart.Chart
With Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
'Change to what your series should be called
.SeriesCollection(1).Name = "theoritical volatility smile at the maturity = one week"
.SeriesCollection(1).XValues = xrng2
.SeriesCollection(1).Values = yrng3
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Strike price"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Theoritical implied vol"
End With
With Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
'Change to what your series should be called
.SeriesCollection(2).Name = "realized volatility smile at the maturity = two week"
.SeriesCollection(2).XValues = xrng2
.SeriesCollection(2).Values = yrng4
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Strike price"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "realized implied vol"
End With
End Sub
Sub plot_smile6()
Dim sh As Worksheet
Set sh = ActiveWorkbook.Worksheets("GBPUSD")
Dim xrng2 As Range
Dim yrng3, yrng4 As Range
Range("L67:L76").Select
11. Set yrng3 = Range("L67:L76")
Range("M67:m76").Select
Set yrng4 = Range("m67:m76")
Range("K67:K76").Select
Set xrng2 = Range("i67:i76")
Dim Chart As Chart
Set Chart = sh.Shapes.AddChart.Chart
With Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
'Change to what your series should be called
.SeriesCollection(1).Name = "theoritical volatility smile at the maturity = one week"
.SeriesCollection(1).XValues = xrng2
.SeriesCollection(1).Values = yrng3
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Strike price"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Theoritical implied vol"
End With
With Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
'Change to what your series should be called
.SeriesCollection(2).Name = "realized volatility smile at the maturity = two week"
.SeriesCollection(2).XValues = xrng2
.SeriesCollection(2).Values = yrng4
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Strike price"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "realized implied vol"
End With
End Sub
Sub plot_smile7()
Dim sh As Worksheet
Set sh = ActiveWorkbook.Worksheets("GBPUSD")
Dim xrng2 As Range
Dim yrng3, yrng4 As Range
12. Range("L80:L89").Select
Set yrng3 = Range("L80:L89")
Range("M80:m89").Select
Set yrng4 = Range("m80:m89")
Range("K80:K89").Select
Set xrng2 = Range("i80:i89")
Dim Chart As Chart
Set Chart = sh.Shapes.AddChart.Chart
With Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
'Change to what your series should be called
.SeriesCollection(1).Name = "theoritical volatility smile at the maturity = one week"
.SeriesCollection(1).XValues = xrng2
.SeriesCollection(1).Values = yrng3
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Strike price"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Theoritical implied vol"
End With
With Chart
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
'Change to what your series should be called
.SeriesCollection(2).Name = "realized volatility smile at the maturity = two week"
.SeriesCollection(2).XValues = xrng2
.SeriesCollection(2).Values = yrng4
.HasTitle = False
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Strike price"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "realized implied vol"
End With
End Sub
The dataset weβve been using for those work:
1.275 1.275 1.275 1.25 1.25 strike price
1.28 1.28 1.28 1.26 1.26
1.285 1.285 1.285 1.27 1.27
1.29 1.29 1.29 1.28 1.28
1.295 1.295 1.295 1.29 1.29
1.3 1.3 1.3 1.3 1.3
16. strike price theotical option price
real
price implied volatility
implied volatility
at exchange
1.25 0.060338522 0.06328 0.107411316 0.0702
1.26 0.052360635 0.05524 0.098835389 0.0688
1.27 0.044472327 0.04729 0.090458671 0.0675
1.28 0.037171529 0.03993 0.083663957 0.0663
1.29 0.030657419 0.03336 0.078969698 0.0653
1.3 0.024989734 0.02764 0.076497233 0.0644
1.31 0.019441487 0.02204 0.074222435 0.0639
1.32 0.015137922 0.01769 0.075186428 0.0636
1.33 0.011471515 0.01398 0.077694386 0.0637
1.34 0.008372494 0.01084 0.081532924 0.0639
0
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.1
1.27 1.28 1.29 1.3 1.31 1.32 1.33
realizedimpliedvol
Strike price
theoritical volatility smile at
the maturity = one week
realized volatility smile at the
maturity = two week
Series3
0
0.02
0.04
0.06
0.08
0.1
0.12
1.24 1.26 1.28 1.3 1.32 1.34 1.36
realizedimpliedvol
Strike price
theoritical volatility smile at
the maturity = one week
realized volatility smile at
the maturity = two week
Series3
17. strike price theotical option price
real
price implied volatility
implied volatility
at exchange
1.25 0.105329702 0.1116 0.172662986 0.081
1.26 0.096513507 0.10265 0.164148748 0.0796
1.27 0.080238077 0.08617 0.140725086 0.077
1.28 0.064792744 0.07053 0.119144066 0.0745
1.29 0.050970838 0.05653 0.100935968 0.0722
1.3 0.038178459 0.04357 0.084875153 0.0701
1.31 0.027655277 0.0329 0.073321094 0.0685
1.32 0.019094644 0.02421 0.065589327 0.0677
1.33 0.012506773 0.01751 0.061620384 0.0674
1.34 0.007653733 0.01256 0.060887743 0.0676
We find that the implied volatilities in market and the volatilities computed are not totally
same.
Besides we also would like to compare the delta in real market and these theoretical,
Here, weβve built the struct which allows us to unfasten some heavy coding work, below is
the code:
===================================================================
Sub calculatedelta()
Dim d As Delta
Set d = New Delta
Dim strike(10, 5) As Double
Dim impexchange(10, 5) As Double
Dim price(10, 5) As Double
Dim impvol() As Double
0
0.02
0.04
0.06
0.08
0.1
0.12
0.14
0.16
0.18
0.2
1.24 1.26 1.28 1.3 1.32 1.34 1.36
realizedimpliedvol
Strike price
theoritical volatility smile at
the maturity = one week
realized volatility smile at
the maturity = two week
Series3
19. Range("f" & b).value = d.delta1(spot, strike(i4, i3 - 2), maturity(i3), rf1, rf2, impvol(i4))
Next i4
Next i3
d.strikeprice = "strike price"
d.theoptionprice = "theoritical option price"
d.realprice = "real price"
d.impliedvol = "implied volatilities"
d.realimpliedvol = "implied volatilities at exchange"
d.optiondelta = "theoritical delta"
d.deltaexchange = "delta at exchange"
'Debug.Print c
'Debug.Print p
For i2 = 3 To 7
a = 1 + (i2 - 3) * 12
Range("a" & a).value = d.strikeprice
Range("b" & a).value = d.theoptionprice
Range("c" & a).value = d.realprice
Range("d" & a).value = d.impliedvol
Range("e" & a).value = d.realimpliedvol
Range("f" & a).value = d.optiondelta
Range("f" & a).Offset(0, 1).value = d.deltaexchange
'Range("j14").Value = "theotical option price"
'Range("k14").Value = "real price"
'Range("l14").Value = "implied volatility"
Next i2
End Sub
===================================================================
Code of Struct object construction (class)
Option Explicit
Private title1, title2, title3, title4, title5, title6, title7 As String
Public Sub Class_initialize()
Worksheets("raw data").Select
End Sub
===================================================================
Public Function delta1(ByVal spot As Double, ByVal strike As Double, maturity As Double,
ByVal rf1 As Double, ByVal rf2 As Double, ByVal vol As Double) As Double
20. Dim a, b As Double
a = WorksheetFunction.Ln(spot / strike) + (rf1 - rf2 + vol * vol * 0.5) * maturity
b = a - vol * Sqr(maturity)
delta1 = WorksheetFunction.Norm_S_Dist(a, True)
End Function
===================================================================
Public Function optionprice(ByVal spot As Double, ByVal strike As Double, maturity As
Double, ByVal rf1 As Double, ByVal rf2 As Double, vol As Double) As Double
Dim a, b As Double
a = WorksheetFunction.Ln(spot / strike) + (rf1 - rf2 + vol * vol * 0.5) * maturity
b = a - vol * Sqr(maturity)
optionprice = spot * Exp(-rf2 * maturity) * WorksheetFunction.NormSDist(Arg1:=a) - strike *
Exp(-rf1 * maturity) * WorksheetFunction.NormSDist(Arg1:=b)
End Function
===================================================================
Function ImpliedVolatility(ByVal spot As Double, ByVal strike As Double, ByVal maturity As
Double, ByVal rf1 As Double, ByVal rf2 As Double, ByVal OptionValue As Double) As Double
Dim epsilon As Double, dVol As Double, vol_1 As Double
Dim i As Integer, maxIter As Integer, Value_1 As Double, vol_2 As Double
Dim Value_2 As Double, dx As Double
dVol = 1E-05
epsilon = 1E-05
maxIter = 1000
Do
Value_1 = optionprice(spot, strike, maturity, rf1, rf2, vol_1)
vol_2 = vol_1 - dVol
Value_2 = optionprice(spot, strike, maturity, rf1, rf2, vol_2)
dx = (Value_1 - Value_2) / dVol
If Abs(dx) < epsilon Or i = maxIter Then Exit Do
vol_1 = vol_1 + (OptionValue - Value_1) / dx
i = i + 1
Loop
ImpliedVolatility = vol_1
End Function
21. ===================================================================
Public Property Let strikeprice(value As String)
title1 = value
End Property
===================================================================
Public Property Get strikeprice() As String
strikeprice = title1
End Property
===================================================================
Public Property Let theoptionprice(value As String)
title2 = value
End Property
===================================================================
Public Property Get theoptionprice() As String
theoptionprice = title2
End Property
===================================================================
Public Property Let realprice(value As String)
title3 = value
End Property
===================================================================
Public Property Get realprice() As String
realprice = title3
End Property
===================================================================
Public Property Let impliedvol(value As String)
title4 = value
End Property
===================================================================
Public Property Get impliedvol() As String
impliedvol = title4
End Property
===================================================================
Public Property Let realimpliedvol(value As String)
title5 = value
End Property
22. ===================================================================
Public Property Get realimpliedvol() As String
realimpliedvol = title5
End Property
===================================================================
Public Property Let optiondelta(value As String)
title6 = value
End Property
===================================================================
Public Property Get optiondelta() As String
optiondelta = title6
End Property
===================================================================
Public Property Let deltaexchange(value As String)
title7 = value
End Property
===================================================================
Public Property Get deltaexchange() As String
deltaexchange = title7
End Property
===================================================================
Below is the results by using the class object and algorithm to get the delta in different
circumstances:
strike
price
theoritical
option price
real
price
implied
volatilities
implied
volatilities at
exchange
theoritical
delta
delta at
exchange
1.275 0.028 0.028 0.080 0.068 0.510 0.830
1.280 0.024 0.024 0.069 0.068 0.508 0.770
1.285 0.020 0.020 0.061 0.067 0.507 0.700
1.290 0.016 0.016 0.054 0.066 0.505 0.620
1.295 0.013 0.013 0.050 0.066 0.504 0.540
1.300 0.010 0.010 0.049 0.066 0.502 0.450
1.305 0.008 0.008 0.050 0.066 0.500 0.370
1.310 0.006 0.006 0.053 0.067 0.499 0.300
1.315 0.005 0.005 0.059 0.067 0.497 0.230
1.320 0.004 0.004 0.067 0.068 0.496 0.180
strike
price
theoritical
option price
real
price
implied
volatilities
implied
volatilities at
exchange
theoritical
delta
delta at
exchange
1.275 0.03114 0.03114 0.075102 0.0659 0.5096419 0.76
1.28 0.02722 0.02722 0.068398 0.0651 0.5080489 0.71
1.285 0.02352 0.02352 0.0627222 0.0644 0.5064691 0.66