Hello,
I am wondering if there is a possible way to change the bolded lines to perform a reference to a previous cell within the For Loop array. An example of how I want the code to perform is commented.
Public Function simStockPrice(sp As Variant, _
mu As Variant, _
sigma As Variant, _
t As Variant, _
dt As Variant) As Variant
Dim i As Integer
Dim sptemp() As Variant
Dim stepCount As Long
' On Error GoTo Errorhandler
With wsP1
stepCount = .Range("C7") * .Range("C8")
End With
ReDim sptemp(0 To stepCount, 1 To 5)
For i = 0 To stepCount
sptemp(i, 1) = i
sptemp(i, 2) = Application.NormSInv(Rnd)
sptemp(0, 3) = sp
sptemp(0, 4) = sp
sptemp(i, 3) = sptemp(i, 3) * Exp((mu - sigma ^ 2 / 2) * (dt / t) + sigma * sptemp(i, 2) * Sqr(dt / t))
sptemp(i, 4) = sptemp(i, 4) * Exp((mu - sigma ^ 2 / 2) * (dt / t))
' sptemp(i + 1, 3) = sptemp(i - 1, 3) * Exp((mu - sigma ^ 2 / 2) * (dt / t) + sigma * sptemp(i, 2) * Sqr(dt / t))
' sptemp(i + 1, 4) = sptemp(i - 1, 4) * Exp((mu - sigma ^ 2 / 2) * (dt / t))
Next
Bookmarks