I am trying to pass a variable from a user form sub to a function. In the userform code, I have defined "cp" as equal to "c". For some reason when I call the function, it is not passing the value cp. How can I pass this value to the function? Thanks
Within the userform sub routine I have these lines of code:
So = 100
K = 120
r = 0.1
v = 0.2
m = 1
cp = "c"
BlackScholesOptionValue.Value = BlackScholes(So, K, m, r, v)
The function is set up as follows:
Function BlackScholes(So As Double, K As Double, m As Double, r As Double, v As Double)
Dim d1 As Double
Dim d2 As Double
Dim cp As String
If cp = "c" Then
d1 = (Log(So / K) + (r + 0.5 * v ^ 2)) / (v * (m ^ 0.5))
d2 = d1 - v * (m ^ 0.5)
BlackScholes = So * Application.NormSDist(d1) - K * Exp(-r * m) * Application.NormSDist(d2)
Else 'cp = "p"
d1 = (Log(So / K) + (r + 0.5 * v ^ 2)) / (v * (m ^ 0.5))
d2 = d1 - v * (m ^ 0.5)
BlackScholes = K * Exp(-r * m) - So + (So * Application.NormSDist(d1) - K * Exp(-r * m) * Application.NormSDist(d2))
End If
End Function
Bookmarks