Vectorized initial values - Simulation

27 Views Asked by At

I want to simulate a certain stochastic process, lets say a geometric brownian motion (in matlab) with various initial values. Let's say, $$S_{0} = [0.01:0.01:1].$$ For every value of $S_{0}$, I want to store a path. Even though I can simulate a path for a specific $S_{0}$, I don't know how to efficiently vectorize initial values. Any ideas?

My idea:

a = [0.01:0.01:1];

for i=1:size(a)

S0(i) = a(i); 
path(i) = GBMPATH(S0(i), T, r, sigma, mu);

end

However, I doesn't work.

1

There are 1 best solutions below

5
On BEST ANSWER

I would store the paths in a matrix where each column contains a path.

Edit: I think that I spotted your mistake which lies in the syntax for the for-loop. If you use MATLAB, which I think you do by the syntax, size(a) = [1,10]. And thus if you want to run i = 1:size(a), it will only take the first argument of size(a) which equals 1. A fix would be to use size(a,2) or length(a).