Professional Documents
Culture Documents
com/local--files/black-schole-european-option-with-gr
eeks/VBA_EuroOption_BlackScholes.txt
Option Compare Database
Option Explicit
'use enum for column OptionType
Public Enum ReturnValue
ValueBS = 1
DeltaBS = 3
GammaBS = 5
ThetaBS = 6
RhoBS = 8
VegaBS = 10
End Enum
'use enum for column OptionType
Public Enum OptionCalculation
Call_BlackSchole = 1
Put_BlackSchole = 2
End Enum
Private
Private
Private
Private
Private
Private
Private
Private
mOptionType As Long
mStrikePrice As Double
mSharePrice As Double
mTimeToExpiry As Double
mRiskFreeInterestRate As Double
mSigma As Double
mDividend As Double
mlngID As Long
mOptionType = 0
mStrikePrice = 0
mSharePrice = 0
mTimeToExpiry = 0
mR = 0
mRiskFreeInterestRate = 0
mSigma = 0
End Sub
Private Sub Class_Terminate()
''use?
End Sub
Public Property Get StrikePrice() As Double
StrikePrice = mStrikePrice
End Property
Public Property Let StrikePrice(dblVal As Double)
'verifies rate is between 0 and 1
If dblVal <= 0 Then
Dividend = mDividend
End Property
Public Property Let Dividend(dblVal As Double)
'verifies dividend is between 0 and 1
If dblVal < 0 Or dblVal > 1 Then
Err.Raise vbObjectError + 512, "European Option", "Dividend must be betw
een 0 and 1"
End If
mDividend = dblVal
End Property
Private Sub Verify()
If mOptionType = 0 Then
Err.Raise vbObjectError + 512, "European Option", "Option type must
be defined."
ElseIf mStrikePrice = 0 Then
Err.Raise vbObjectError + 512, "European Option", "Strike Price must
be defined."
ElseIf mSharePrice = 0 Then
Err.Raise vbObjectError + 512, "European Option", "Share Price must
be defined."
ElseIf mTimeToExpiry = 0 Then
Err.Raise vbObjectError + 512, "European Option", "Time to Expiry mu
st be defined."
ElseIf mRiskFreeInterestRate = 0 Then
Err.Raise vbObjectError + 512, "European Option", "Risk Free Interes
t Rate must be defined."
ElseIf mSigma = 0 Then
Err.Raise vbObjectError + 512, "European Option", "Sigma (Standard D
eviation) must be defined."
End If
End Sub
Public Function Calculate(ByVal Command As ReturnValue) As Double
' Calculates the value of an European Option (Black-Scholes)
' Typ -> Call or Put
' Command -> Price, Delta, Gamma, Theta, Vega, Rho
Verify
mTimeToExpiry = Excel.WorksheetFunction.Max(0.00001, mTimeToExpiry)
Dim d1 As Double
Dim d2 As Double
Dim dblTempHolder As Double
dblTempHolder = 0
If (mSigma * mStrikePrice * mTimeToExpiry > 0) Then
d1 = Log(mSharePrice / mStrikePrice) + ((mRiskFreeInterestRate - mDivide
nd) + 0.5 * mSigma * mSigma) * mTimeToExpiry
d1 = d1 / (mSigma * Sqr(mTimeToExpiry))
d2 = d1 - mSigma * Sqr(mTimeToExpiry)
End If
Select Case Command
Case ValueBS
If mOptionType = Call_BlackSchole Then
Calculate = (mSharePrice * Exp(-mDividend * mTimeToExpiry) * Cum
ulativeDistributionFunction(d1)) - (Exp(-mRiskFreeInterestRate * mTimeToExpiry)
* mStrikePrice * CumulativeDistributionFunction(d2))
ElseIf mOptionType = Put_BlackSchole Then
Calculate = Exp(-mRiskFreeInterestRate * mTimeToExpiry) * mStrik
ePrice * CumulativeDistributionFunction(-d2) - mSharePrice * Exp(-mDividend * mT
imeToExpiry) * CumulativeDistributionFunction(-d1)
End If
Case DeltaBS
If mOptionType = Call_BlackSchole Then
Calculate = Exp(-mDividend * mTimeToExpiry) * CumulativeDistribu
tionFunction(d1)
ElseIf mOptionType = Put_BlackSchole Then
Calculate = Exp(-mDividend * mTimeToExpiry) * (CumulativeDistrib
utionFunction(d1) - 1)
End If
Case GammaBS
Calculate = nprime(d1) * Exp(-mDividend * mTimeToExpiry) / (mSharePr
ice * mSigma * Sqr(mTimeToExpiry))
Case ThetaBS
End Function
Private Function CumulativeDistributionFunction(x As Double) As Double
Dim
Dim
Dim
Dim
d
a
b
c
As
As
As
As
d
a
b
c
=
=
=
=
Double
Double
Double
Double
1 / (1 + 0.33267 * Abs(x))
0.4361836
-0.1201676
0.937298