I am trying to create a MATLAB code that simulates trajectories of a constant elasticity of variance process (CEV).
My code is below.
M = 5000;
N = 250;
X0 = 100;
T = 1;
a = 0.7;
dt = T/N;
X(1:M,1) = X0;
for j = 1:M
for i = 2:N+1
X(j,i) = 0.02*X(j,i-1)*dt + 0.15*X(j,i-1)^a*sqrt(dt)*randn;
end
end
t = 0:dt:T;
plot(t,X(:,:));
However, when I run the code the following warning message appears,
Warning: Imaginary parts of complex X and/or Y arguments ignored In ConstantElasticyVariance (line 19)
and weird straight lines are shown in the plot.
What am I doing wrong?