# What is wrong in this GBM simulation?

I am trying to generate a few samples of GBM using the following very simple MATLAB code:

function results=gbm(mean,vol,s0,T,shocks)
results = s0 * exp( (mean - vol^2/2) * T + vol^2 * sqrt(T) * shocks);


As you can see, I am using directly the closed form solution of the wiki page.

The thing is, I know that techincally $\mathbb{E}(S_t) = S_0 \exp(\mu t)$, but when I do:

 mean(gbm(0,.1,100,1,randn(1000,1)))


I get 99.54 as a result. How can that be?

I mean in the code above, I use $\mu=0$, so I'm expecting $\mathbb{E}(S_t) = S_0 \exp(0 )=S_0$

I've been looking at this too much and there might be something obvious I'm missing here.

• you should plot that in time, probably will help.second, 99.54 is very close to S(0) = 100, so maybe it need more samples to converge – Svisstack Sep 3 '14 at 15:27
• @Svisstack what do you mean plot in time? No even if I use 100'000 runs it stays close to 99.5. I don't get it. – SRKX Sep 3 '14 at 15:32
• Simply: exp(-0.1^2/2) = 0.9950125 – Joshua Ulrich Sep 3 '14 at 15:36
• @JoshuaUlrich I agree, but still I don't get what is wrong with the implementation VS theoretical result $\mathbb{E}(S_t)=S_0$... – SRKX Sep 3 '14 at 15:38

Its $$\sqrt{\sigma^2T}=\sigma\sqrt{T}$$