# Problem with iterations of Prepend/While

I am doing some work with black-scholes and am trying to find random interest rates based on some given information. This is my original code:

dt = .0001;
mu = 0;
gamma = .005;
t = .0833;
random = RandomVariate[NormalDistribution[0, dt^.5], 10^2];
Z = Table[0, 10^2 + 1];
Z[] = .0158;
i = 2;
While[i <= 834,
Z[[i]] = Z[[i - 1]] + mu*dt + (gamma)*random[[i - 1]];
i++
];
(*have to make this loop 100 times*)
ListPlot[Z, DataRange -> {0, 100*dt}, PlotRange -> All];
Print[Z];


My main goal is just to get the list of values for interest rates that should be seen as 100X834 in table form. I've received the following revision to my code, from stack exchange, however it isn't outputting the correct table form that I need, I am not sure if I need to put Prepend into my while loop to get it to iterate correctly, or how I can control the dimensions of the table to give me the amount of values I need.

dt = .0001;
mu = 0;
gamma = .005;
t = .0833;
rndm := RandomVariate[NormalDistribution[0, dt^.5], 10^2];
Prepend[Accumulate[rndm] gamma + mu dt + .0158, .0158];
k = 100;
SeedRandom
W = Table[Prepend[Accumulate[rndm] gamma + mu dt + .0158, .0158],
k];

• If it results in a more readable approach to you, your While loop could also be replaced by a FoldList call, with your value of Z[] as a starting point, and rndm as the list to be folded in. Dec 22 '19 at 4:54
• replace 10^2 with 834 in rndm := RandomVariate[NormalDistribution[0, dt^.5], 10^2];?
– kglr
Dec 22 '19 at 5:00
• ahh completely forgot that the table was defined to that width, it worked thanks! Dec 22 '19 at 15:11

You may use GeometricBrownianMotionProcess with RandomFunction. You may also find the Stochastic Differential Equation Processes guide useful.

mu = 0;
gamma = .005;
z0 = .0158;
dt = .0001;
steps = 834;
SeedRandom
walk = RandomFunction[
GeometricBrownianMotionProcess[mu, gamma, z0], {0, steps dt, dt}] This returns a TemporalData object that can be plotted with ListLinePlot and other functions.

ListLinePlot[walk] n paths can be generated with

n = 5;
SeedRandom
walks = RandomFunction[
GeometricBrownianMotionProcess[mu, gamma, z0], {0, steps dt, dt}, n]
ListLinePlot[walks]  Time steps and values can be extracted by the "Paths", "Values", and "Components" properties of TemporalData; see TemporalData's documentation.

Hope this helps.