![]() |
Please let me know the error in this code
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 |
Please let me know the error in this code
On Feb 17, 2:52*am, vbaseeker wrote:
Please let me know the error in this code with syntax error in function line. [....] 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 [....] *End Function End Sub You cannot nest procedures -- you cannot put a function inside a sub. Simply remove the lines Sub Montecarlo() and End Sub. But I did not bother read, much less test, the function itself to see if there are other errors. I simply confirmed that removing the sub- related lines eliminates all syntax errors, after I correct the lines folded in the posting without continuation characters. |
All times are GMT +1. The time now is 12:04 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com