# Why is my Euler discretization error increasing with number of steps?

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

• surely it should increase with the step size? Sep 20 '15 at 11:58
• Sorry, ofcourse I mean increasing number of steps (so decreasing stepsize), if N increases one expects the euler method to become more accurate, so X to be closer to Y. Sep 20 '15 at 12:30

## 1 Answer

After thinking about it a bit more I realized what the problem is. Y is generated with different increments than X, while I should use the same. I fixed this and know it is decreasing.

• You should include the correct version of the code in your answer an mark it as accepted.
– SRKX
Dec 21 '15 at 2:57