Stochastic delay differantial equations
조회 수: 2 (최근 30일)
이전 댓글 표시

ı 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?
댓글 수: 0
답변 (1개)
Divija Aleti
2021년 6월 24일
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
miqin
2023년 1월 2일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!