Hi there,
my code is not awesome at the moment I wrote a code to calculate the black scholes formula in an array with all the inputs in different ranges. However, its not working right now and I am stuck at my debugging process. Can anyone please help? Please note that there are two UDFs below. The second UDF called "dOne" is used in the first one.
my code is not awesome at the moment I wrote a code to calculate the black scholes formula in an array with all the inputs in different ranges. However, its not working right now and I am stuck at my debugging process. Can anyone please help? Please note that there are two UDFs below. The second UDF called "dOne" is used in the first one.
Code:
Public Function CallOptArray(spot As Range, strk As Range, time As Range, rate As Range, Vol As Range, Div As Range) As Variant
Dim sArr As Variant
Dim kArr As Variant
Dim tArr As Variant
Dim rArr As Variant
Dim vArr As Variant
Dim dArr As Variant
Dim n As Long
Dim CallPxArr() As Variant
sArr = spot.Value2
kArr = strk.Value2
tArr = time.Value2
rArr = rate.Value2
vArr = Vol.Value2
dArr = Div.Value2
ReDim CallPxArr(1 To UBound(sArr, 1))
On Error GoTo FuncFail
For n = 1 To UBound(sArr, 1)
CallPxArr(n) = Exp(-1 * dArr(n) * tArr(n)) * sArr(n) * Application.NormSDist(dOne(sArr(n), kArr(n), tArr(n), rArr(n), vArr(n), dArr(n))) - kArr(n) * Exp(-1 * rArr(n) * tArr(n)) * Application.NormSDist(dOne(sArr(n), kArr(n), tArr(n), rArr(n), vArr(n), dArr(n)) - vArr(n) * Sqr(tArr(n)))
Next n
CallOptArray = CallPxArr
FuncFail:
MsgBox ("Dude..")
End Function
Function dOne(spot, strk, time, rate, Vol, Div)
dOne = (Log(spot / strk) + (rate - Div + 0.5 * Vol ^ 2) * time) / (Vol * (Sqr(time)))
End Function
Last edited by a moderator: