Public Function ForwardEuler( _ ByVal s0 As Double, _ ByVal k As Double, _ ByVal T As Double, _ ByVal sigma As Double, _ ByVal r As Double, _ ByVal periods As Integer) ' Use the forward Euler trinomial tree method to price an option DelT = T / periods ' The size of a time period do that n equal periods fit delX = sigma * Sqr(DelT) ' The size of the space step if . . . Xmin = -periods * delX ' The minimum value of x on the computational grid If periods > 200 Then ' The VBA syntax for the "if" test. Here return if you don't ' have memory for that many time steps. ForwardEuler = -0.12345 ' return a silly value that hopefully would be recognized Return ' stop the program here. End If Dim f(-200 To 200, 200) As Double ' The VBA syntax for dimensioning an array. Note that the ' range of the j index is -period to period and the n index ' is from 1 to period. "Double" is the type. For j = -periods To periods ' The VBA syntax for the start of a "for" loop. x = delX * j ' Calculate the final values . . . IntVal = x ' not the right formula If (IntVal < 0) Then f(k, periods) = 0 ' and put them in the appropriate place in the f array Else f(k, periods) = IntVal End If Next j ' The end of the "for" loop. a = 0.3333 ' not the real coefficients. b = 0.3333 c = 0.3333 For n = periods To 2 Step -1 ' This goes from the end to the beginning in steps of -1 For j = -(n - 1) To (n - 1) ' You can put a loop inside another loop f(j, n - 1) = a * f(j + 1, n) + b * f(j, n) + c * f(j + 1, n) ' The actual formula Next j Next n ForwardEuler = f(0, 1) ' You return a value by assigning the function name the desired value. ' here j = 0 means spot price, n=1 means start time. End Function Public Function BlackScholesEuropeanPut( _ ByVal s0 As Double, _ ByVal k As Double, _ ByVal T As Double, _ ByVal sigma As Double, _ ByVal r As Integer) BlackScholesEuropeanPut = Application.WorksheetFunction.NormSDist(s0) ' This is how you access the ' Excel function NormSDist from VBA. End Function