Milstein's high order method graph stays at 0
Show older comments
I'm trying to graph the following SDE: dX = rX(K-X)dt +beta*sqrt(X)*dW using the following code:
rand('state',100);
beta = 0.25;
r = 1; K = 10; X0 = K; %problem parameters
T = 1; N = 2^11; dt = T/N;
dW = sqrt(dt)*randn(N,N);
Xmil = zeros(N,1);
for i = 1:N
Winc = sum(dW(:,i));
Xmil = Xmil + dt*r*Xmil.*(K-Xmil) + beta*(Xmil.^0.5).*Winc + 0.5*(beta^2)*(Xmil.^0.5).*(Winc.^2 - dt);
end
Dt = zeros(N,1); %building an array for the time values we have taken
for j = 2:N
Dt(j) = j*dt;
end
plot(Dt, Xmil);
title('Solution of The Equation using Milstein Method')
xlabel('t');ylabel('X(t)');
however the graph keeps staying at 0 for every value of beta I'm inputing.
1 Comment
Amit R
on 30 Mar 2021
Answers (1)
Alan Stevens
on 30 Mar 2021
Your line
Xmil = Xmil + dt*r*Xmil.*(K-Xmil) + .....
probably needs to be
Xmil(i+1) = Xmil(i) + dt*r*Xmil(i).*(K-Xmil(i)) + .... etc.
However, if this is the case, you will still need a non-zero initial value for Xmil, or all terms will inevitably stay at zero!
Categories
Find more on Stochastic Differential Equation (SDE) Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!