I'm trying to see how the Euler discretization error behaves with respect to the number of steps. To do this I'm simulating a geometric brownian motion and comparing it with it's 'exact' solution. However when using the root mean squared error as a measure of the error it is increasing with the number of steps, which is very weird! So now I'm confused if I made a coding error or I'm just missing something. Help would be appreciated!
Here is my matlab code, I hope it is self explanatory. (The problem is that the elements of meanvec are increasing while it is expected they decrease)
X0=100; mu=0.04; sigma=0.2; T=10; M=10^5; meanvec=zeros(6,1); for i=1:6 N=2^i; dt=T/N; t=0; X=X0; for k=1:N dW = sqrt(dt)*randn(M,1); dX = mu*X*dt + sigma*X.*dW; X = X + dX; t = t + dt; end Y=100.*exp((mu-sigma^2/2)*T+sigma.*sqrt(T).*randn(M,1)); meanvec(i)=sqrt(mean((X-Y).^2))/mean(Y); end