Stochastic delay differantial equations

18 visualizzazioni (ultimi 30 giorni)
miray boldan
miray boldan il 21 Giu 2021
Commentato: miqin il 2 Gen 2023
ı write this matlab code but it doesnt work.
% Euler-Maruyama method on linear SDE Stock Price.
%SDE is dS= ((mu*S)+(c*S(t-tau)-d) dt + ((a*S)+(b*S(t-tau))dW, S(0) = Szero,
%where mu = -3, c = 2e^-1 , d = 3-2e^-1 , a= 0.1 , b= 0.1 , tau = 1 and Szero = 100.
%Discretized Brownian path over [0,1] has dt = 2^(-8).
%Euler-Maruyama uses timestep R*dt.
randn('state',100)
mu = -3; a = 0.1 ; b = 0.1 ; Szero = 100;
T = 2; N = 2^8; dt = 1/N;
dW = sqrt(dt)*randn(1,N);
W = cumsum(dW);
%Strue = Szero*exp((mu-0.5*sigma^2)*([dt:dt:T])+sigma*W);
%plot([0:dt:T],[Szero,Strue],'m-'), hold on
R =8; Dt = R*dt; L = N/R;
Xem = zeros(1,L);
Xtemp = Szero;
linetypes={'b-','g--*'};
for j = 1:L
Winc = sum(dW(R*(j-1)+1:R*j));
Xtemp = Xtemp + Dt*mu*Xtemp + a*Xtemp*Winc;
Xem(j) = Xtemp;
end
plot([0:Dt:T],[Szero,Xem],'g--*'), hold off
legend(': Exact solution',': Euler-Maruyama')
xlabel('t','FontSize',12)
ylabel('S','FontSize',12,'Rotation',0,'HorizontalAlignment','right')
emerr = abs(Xem(end)-Strue(end))
what is my mistake?

Risposte (1)

Divija Aleti
Divija Aleti il 24 Giu 2021
Hi Miray,
The error is occurring in the line where you are using the plot function. This is because the values you have given to the function are of different lengths.
0:Dt:T has 65 elements whereas [Szero,Xem] has 33 elements.
To use the plot function, both these vectors should be of the same length.
I suggest you to review your problem statement, all the variable values and the code you have written to figure out which of the above vectors should be changed.
Hope this helps!
Regards,
Divija
  2 Commenti
miqin
miqin il 2 Gen 2023
Hi Divija,
It's nice to see your answer to the above question. I have a similar problem and want to get your help. The following is a stochastic differential equation group with time delay. I want to draw Fig. 4 but do not know how to write a Matlab program. Parameter values are as follows : r = 0.5 ; b = 0.6 ; c1 = 0.6 ; c2 = 0.5 ; d = 0.2 ; h = 0.8 ; β = 0.4.
Thanks!
Regards,
Cmq

Accedi per commentare.

Categorie

Scopri di più su Time Series Objects in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by