Serving the Quantitative Finance Community

 
User avatar
strategos
Topic Author
Posts: 0
Joined: January 24th, 2002, 6:15 pm

MATLAB: Simulated Geometric Brownian Motion with too small std

June 23rd, 2006, 5:37 pm

Hi, I am trying to generate GBM in MATLAB with a Cholesky decomposition thrown in to ensure that the random numbers are really N(0,1) distributed. Try as I might, I can't get the standard deviation of the generated time series to come close to that of the input standard deviation. It is constantly is too small by a factor of around 3 -5. I have checked out the setting of the random number generator, and that isn't causing the problem. What I am missing here, any known issues? Thanks for your help, strategos % GBM(mean,sigma,n,T) simulates a geometric Brownian motion % on [0,T] using n normally distributed steps and parameters mean and% sigma; function [X] = GBM(mu,sigma,n,T) t = (0:1:n-1)'/n; t = t*T; % ensure N(0,1) distribution RNraw = randn(n-1,1); M = mean(RNraw); S = cov(RNraw); RNcorr = (RNraw-M)*inv(chol(S)); W = [0; cumsum(RNcorr)]/sqrt(n-1); W = W*sqrt(T); % analytical solution to GBM X = exp((mu-(sigma^2)/2).*t + sigma * W);
 
User avatar
JPB
Posts: 0
Joined: June 21st, 2006, 9:07 am

MATLAB: Simulated Geometric Brownian Motion with too small std

July 2nd, 2006, 7:13 pm

Hi Strategos,Your code produces n-1 time intervals of length T/n. Your time vector is then made of n values ranging from t=0 to t=T*(n-1)/n.Comments:1. Is it normal it does not go to T ?2. To check your re-correlation code, did you replace RNcorr by RNraw to calculate W ? Do you still find the same vol discrepancy ?3. What calculations do you do to calculate the effective vol of your process ?Note: In the past, I have used randn in several simulations. I have not so far spotted any major flaws for this function.
 
User avatar
strategos
Topic Author
Posts: 0
Joined: January 24th, 2002, 6:15 pm

MATLAB: Simulated Geometric Brownian Motion with too small std

July 8th, 2006, 11:03 pm

Hi JPB,Thanks for your comments. a) You can simulate for several T, but the std and mean should be achieved on average for, say, more than 30 simulations (Central Limit Theorem). The first period is set to 0 so that the process starts at 1 and stochastic behaviour follows.b) I tried your suggestion before, but it wasn't the Cholesky that was affecting the std dev. Vol discrepancy was still the same, too low by a factor of 3-4. The mean of the realised time series is nicely distributed around the input mean, its just the stdc) I use the Matlab function std(X) = Y. I agree that the Matlab RNG is actually very good. I tested it against the Mersenne Twister of Matsumoto and Nishimura, which many investment banks use as their workhorse RNG. (ACM Transactions on Modeling and Compuer Simulations 1998: "Mersenne Twister: A 623-dimensionally equidistributed uniform pseudorandom number generator"). Using very elementary QQ-plots it seemed that at least in 2 and 3 dimensions the MATLAB RNG performed better. However, I have been told that QQ-plots aren't a very strong test of distribution.Any further thoughts you have are appreciated.Strategos
Last edited by strategos on July 11th, 2006, 10:00 pm, edited 1 time in total.
 
User avatar
vixen
Posts: 0
Joined: April 5th, 2006, 1:43 pm

MATLAB: Simulated Geometric Brownian Motion with too small std

July 10th, 2006, 8:39 am

Why do you divide by sqrt(n-1)?Without that, it is fine. And std(diff(log(X)))/sqrt(T) always returns sigma
 
User avatar
JPB
Posts: 0
Joined: June 21st, 2006, 9:07 am

MATLAB: Simulated Geometric Brownian Motion with too small std

July 10th, 2006, 9:29 am

Strategos,I have just realised that this line X = exp((mu-(sigma^2)/2).*t + sigma * W) is not right.Here you do not diffuse the variable X(t) starting at t = 0 [X(0)=1] on n-1 intervals of length T/n.You draw n-1 times a variable X(t) starting a t = 0 [X(0)=1] and ending at t = T/n.
 
User avatar
strategos
Topic Author
Posts: 0
Joined: January 24th, 2002, 6:15 pm

MATLAB: Simulated Geometric Brownian Motion with too small std

July 16th, 2006, 1:34 pm

@ vixen: dividing by sqrt(n-1) is the same as multiplying by sqrt(1/n-1), I am quite sure you have to scale the shocks infinitesimally as well.@ JPB: there are actually $n$ intervals on which I diffuse X(t), since t and W start at zero. I'm not quite getting your point, since vectorized operations should ensure that the sequence in t and W is preserved. I don't see my code drawing anything in the line you mention. Maybe you can clarify? Thanks, S.
Last edited by strategos on July 15th, 2006, 10:00 pm, edited 1 time in total.