V
vbaseeker
Hello all,
I am beginner in VBa programming.
Please let me know the error in this code with syntax error in
function line.
Thanks in advance!!!
Sub Montecarlo()
Function callPriceMC(s0 As Double,k As Double, T As Double,r As
Double, q As Double, vol As Double,
numTrials As Long, seed As Long) As Double
Rnd (-20)
Randomize (seed)
Dim i As Long
Dim g As Double
Dim st As Double
callPriceMC = 0
For i = 1 To numTrials
g = Application.WorksheetFunction.NormSInv(Rnd())
st = s0 * Exp((r - q - vol * vol / 2) * T + g * vol * Sqr(T))
callPriceMC = callPriceMC + Application.WorksheetFunction.Max(st - k,
0)
Next i
callPriceMC = callPriceMC * Exp(-r * T) / numTrials
End Function
End Sub
I am beginner in VBa programming.
Please let me know the error in this code with syntax error in
function line.
Thanks in advance!!!
Sub Montecarlo()
Function callPriceMC(s0 As Double,k As Double, T As Double,r As
Double, q As Double, vol As Double,
numTrials As Long, seed As Long) As Double
Rnd (-20)
Randomize (seed)
Dim i As Long
Dim g As Double
Dim st As Double
callPriceMC = 0
For i = 1 To numTrials
g = Application.WorksheetFunction.NormSInv(Rnd())
st = s0 * Exp((r - q - vol * vol / 2) * T + g * vol * Sqr(T))
callPriceMC = callPriceMC + Application.WorksheetFunction.Max(st - k,
0)
Next i
callPriceMC = callPriceMC * Exp(-r * T) / numTrials
End Function
End Sub