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:


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.

  • $\begingroup$ 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 $\endgroup$
    – Svisstack
    Sep 3, 2014 at 15:27
  • $\begingroup$ @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. $\endgroup$
    – SRKX
    Sep 3, 2014 at 15:32
  • $\begingroup$ Simply: exp(-0.1^2/2) = 0.9950125 $\endgroup$ Sep 3, 2014 at 15:36
  • $\begingroup$ @JoshuaUlrich I agree, but still I don't get what is wrong with the implementation VS theoretical result $\mathbb{E}(S_t)=S_0$... $\endgroup$
    – SRKX
    Sep 3, 2014 at 15:38

1 Answer 1


You have typo "vol^2", but it should be "vol".

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

  • $\begingroup$ Oh thanks how did I miss that. I could have look 10 more hours at this... $\endgroup$
    – SRKX
    Sep 3, 2014 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.