Saturday, April 11, 2015

programming - 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.



Answer




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


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


No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...