Goodmorning. I'm new here. Before posting I've searched similar questions, but I found something similar only with different programming language, and however the question found were incomplete.
Ok, my problem is to find a VBA code which, once recalled in Excel, it requires from me only the Geometric Brownian Motions (GBM) parameters (initial stock value s, maturity t, volatility z, risk-free rate r, dividend q, number of steps n), the number m of trajectories I need to reproduce. As a output I don't want to see no numbers, only one plot of the superimposed m trajectories.
The problem is that, I can't write it directly cell by cell (then carrying) because in this way it would be too complex from a computational power point of view; it would allow to make something like 15 trajectories, not much more. Thus the solution is to work in VBA.
My initial step was
Function GBMSimulation(s As Double, t As Double, z As Double, r As Double, q As Double, n As Double) As Variant
Dim dt, e, dlns, SimVar() As Double
ReDim SimVar(n + 1)
dt = t / n
SimVar(0) = s
For i = 1 To n
Randomize
e = WorksheetFunction.NormSInv(Rnd())
dlns = (r - q - z ^ 2 / 2) * dt + z * e * dt ^ 0.5
SimVar(i) = SimVar(i - 1) * Exp(dlns)
Next i
GBMSimulation = SimVar(n)
End Function
This code works; I mean, it gives a number, which is the n-th step of ONE gbm.
Changing
GBMSimulation = SimVar(n)
with
GBMSimulation = SimVar(i)
I would obtain the i-th step of that particular gbm.
Thus, all the steps are stored in memory and this is good.
My problem is: how can I create m different realizations of a GBM (i.e. to repeat my previous step m times, m given as an input) and for each one of them create automatically a plot?
I think some for cycle should be taken into account, but I'm a beginner and I don't know how to do this.
I thought I could create an n-dimensional array in which store the GBM steps, plotting them, and repeat this m times; the problem is that I miss the language, I'm learning it, but it require time, and some help could be useful.
ONLY FROM GRAPHICAL POINT OF VIEW, the final result should be like this (I specified the graphical pov because in the link there are numbers, and all the work is made cell by cell, and as I said before I need to avoid this).
Many thanks.
UPDATE: my problem was partially solved thank to Tehscript. The code he/she kindly provided, allows to store the n steps of each of the m GBMs in an array of arrays. Thus remains one last step in order to solve my problem: how can I plot these datas?