prakash_moturu
Board Regular
- Joined
- Nov 2, 2009
- Messages
- 152
Hi
i am calculating the delta value to change the e2 or f2 values.
after change the e2 and f2 value, i am calling CallDelta() method with required
parameters.it fires CallDelta() method but it shows same output if the
e2 and f2 values are changed.
example :
e2 0r f2 =33 0r 66 the msgbox shows =0.9999999 why?
and next question is in sheet1 clear button press the change event is not working?
please any body send your valuable sugittions
module code
please help me in this issue
i am calculating the delta value to change the e2 or f2 values.
after change the e2 and f2 value, i am calling CallDelta() method with required
parameters.it fires CallDelta() method but it shows same output if the
e2 and f2 values are changed.
example :
e2 0r f2 =33 0r 66 the msgbox shows =0.9999999 why?
and next question is in sheet1 clear button press the change event is not working?
please any body send your valuable sugittions
Code:
Private Sub CommandButton1_Click()
Sheet1.Range("A2").Value = ""
Sheet1.Range("b2").Value = ""
Sheet1.Range("c2").Value = ""
Sheet1.Range("d2").Value = ""
Sheet1.Range("e2").Value = ""
Sheet1.Range("f2").Value = ""
Sheet1.Range("g2").Value = ""
Sheet1.Range("h2").Value = ""
Sheet1.Range("i2").Value = ""
Sheet1.Range("j2").Value = ""
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim optprice, vol, del, ga, ve, the, undpr, strkpri, dte, riskrate, div
div = 0
dte = 0.06
riskrate = 0
Dim caldel, calve, calga, calthe As Variant
If Not Intersect(Range("E2,F2"), Target) Is Nothing Then
If Target.Count = 1 Then
Application.EnableEvents = False
undpr = Sheet1.Range("B2").Value
strkpri = Sheet1.Range("c2").Value
optprice = Sheet1.Range("E2").Value
vol = Sheet1.Range("f2").Value
caldel = CallDelta(undpr, strkpri, dte, riskrate, vol, div)
MsgBox "caldelta" & caldel
End If
Application.EnableEvents = True
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub
module code
Code:
Function dOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
dOne = (Log(UnderlyingPrice / ExercisePrice) + (Interest - Dividend + 0.5 * Volatility ^ 2) * Time) / (Volatility * (Sqr(Time)))
End Function
Function NdOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
NdOne = Exp(-(dOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend) ^ 2) / 2) / (Sqr(2 * 3.14159265358979))
End Function
Function dTwo(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
dTwo = dOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend) - Volatility * Sqr(Time)
End Function
Function NdTwo(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
NdTwo = Application.NormSDist(dTwo(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend))
End Function
Function CallOption(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
CallOption = Exp(-Dividend * Time) * UnderlyingPrice * Application.NormSDist(dOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)) - ExercisePrice * Exp(-Interest * Time) * Application.NormSDist(dOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend) - Volatility * Sqr(Time))
End Function
Function PutOption(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
PutOption = ExercisePrice * Exp(-Interest * Time) * Application.NormSDist(-dTwo(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)) - Exp(-Dividend * Time) * UnderlyingPrice * Application.NormSDist(-dOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend))
End Function
Function CallDelta(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
CallDelta = Application.NormSDist(dOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend))
'CallDelta = Application.NormSDist((Log(UnderlyingPrice / ExercisePrice) + (Interest - Dividend) * Time) / (Volatility * Sqr(Time)) + 0.5 * Volatility * Sqr(Time))
End Function
Function PutDelta(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
PutDelta = Application.NormSDist(dOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)) - 1
'PutDelta = Application.NormSDist((Log(UnderlyingPrice / ExercisePrice) + (Interest - Dividend) * Time) / (Volatility * Sqr(Time)) + 0.5 * Volatility * Sqr(Time)) - 1
End Function
Function CallTheta(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
CT = -(UnderlyingPrice * Volatility * NdOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)) / (2 * Sqr(Time)) - Interest * ExercisePrice * Exp(-Interest * (Time)) * NdTwo(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
CallTheta = CT / 365
End Function
Function Gamma(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
Gamma = NdOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend) / (UnderlyingPrice * (Volatility * Sqr(Time)))
End Function
Function Vega(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
Vega = 0.01 * UnderlyingPrice * Sqr(Time) * NdOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
End Function
Function PutTheta(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
PT = -(UnderlyingPrice * Volatility * NdOne(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)) / (2 * Sqr(Time)) + Interest * ExercisePrice * Exp(-Interest * (Time)) * (1 - NdTwo(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend))
PutTheta = PT / 365
End Function
Function CallRho(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
CallRho = 0.01 * ExercisePrice * Time * Exp(-Interest * Time) * Application.NormSDist(dTwo(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend))
End Function
Function PutRho(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)
PutRho = -0.01 * ExercisePrice * Time * Exp(-Interest * Time) * (1 - Application.NormSDist(dTwo(UnderlyingPrice, ExercisePrice, Time, Interest, Volatility, Dividend)))
End Function
Function ImpliedCallVolatility(UnderlyingPrice, ExercisePrice, Time, Interest, Target, Dividend)
High = 5
Low = 0
Do While (High - Low) > 0.0001
If CallOption(UnderlyingPrice, ExercisePrice, Time, Interest, (High + Low) / 2, Dividend) > Target Then
High = (High + Low) / 2
Else: Low = (High + Low) / 2
End If
Loop
ImpliedCallVolatility = (High + Low) / 2
End Function
Function ImpliedPutVolatility(UnderlyingPrice, ExercisePrice, Time, Interest, Target, Dividend)
High = 5
Low = 0
Do While (High - Low) > 0.0001
If PutOption(UnderlyingPrice, ExercisePrice, Time, Interest, (High + Low) / 2, Dividend) > Target Then
High = (High + Low) / 2
Else: Low = (High + Low) / 2
End If
Loop
ImpliedPutVolatility = (High + Low) / 2
End Function
Sub greeks()
End Sub
please help me in this issue