The dynamics of the Geometric Brownian Motion (GBM) are described by the following stochastic differential equation (SDE):

I can use the **exact** solution to the SDE

to generate paths that follow a GBM.

Given daily parameters for a year-long simulation

```
mu = 0.08/250;
sigma = 0.25/sqrt(250);
dt = 1/250;
npaths = 100;
nsteps = 250;
S0 = 23.2;
```

we can get the Brownian Motion (BM) `W`

starting at 0 and use it to obtain the GBM starting at `S0`

```
% BM
epsilon = randn(nsteps, npaths);
W = [zeros(1,npaths); sqrt(dt)*cumsum(epsilon)];
% GBM
t = (0:nsteps)'*dt;
Y = bsxfun(@plus, (mu-0.5*sigma.^2)*t, sigma*W);
Y = S0*exp(Y);
```

Which produces the paths

```
plot(Y)
```

This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0

This website is not affiliated with Stack Overflow