Hi, I need help with my vba code. I know this is a little specific, but if anyone can help it would be amazing.
I need to consider the random market model as a description of the temporal evolution of the price (which would be in log) of a financial asset:
p t = p t-1 + ε t , t = 2, . . . , T,
with p 1 = 0 and where the ε t are N(0, 1) independent variables.
I tried to write a function (Function) that receives as input a value of T and returns a Monte-Carlo estimate of the expected number of times that the price crosses z'ero (i.e. the expected number of times that { p t-1 < 0 and p t > 0 } or { p t-1 > 0 and p t < 0 } ) 'given the value of T. I need to use at least 1000 Monte-Carlo replications. This is the code I wrote, but when I try to test it with a sub procedure, its not working. Can someone help me please?
I need to consider the random market model as a description of the temporal evolution of the price (which would be in log) of a financial asset:
p t = p t-1 + ε t , t = 2, . . . , T,
with p 1 = 0 and where the ε t are N(0, 1) independent variables.
I tried to write a function (Function) that receives as input a value of T and returns a Monte-Carlo estimate of the expected number of times that the price crosses z'ero (i.e. the expected number of times that { p t-1 < 0 and p t > 0 } or { p t-1 > 0 and p t < 0 } ) 'given the value of T. I need to use at least 1000 Monte-Carlo replications. This is the code I wrote, but when I try to test it with a sub procedure, its not working. Can someone help me please?
VBA Code:
Function Question3(tTime As Integer)
Dim tTime As Integer
tTime = T
Dim priceStock(1 To T) As Double
priceStock = pS
Dim ePs As Variant
Dim Index As Integer
Dim Succes As Integer
pS(1) = 0
ePs = Application.NormSInv(Rnd)
pS(T) = pS(T - 1) + ePs(t)
For Index = 1 To 10000
For T = 2 To T
Randomize
If pS(1) < 0 Then Succes = Succes + 1
If pS(T - 1) > 0 Then Succes = Succes + 1
Else
pS(T) = 0
End If
Next T
Next Index
End Function