How can I code a stochastic equation with jumps?
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am able to code Brownian motion seperately and Poisson process seperately. But I need to construct a stochastic differential equation with drift coefficient is zero . diffusion coefficient is 1 and jump coefficient is 1. But the SDE with jumps simulation.
I need to plot . X_{t}=x+W_{t} + \int_{E} N(ds,de)
for brownian
randn('state',100)
T=1;
N=500;
dt=T/N;
dW=sqrt(dt)*randn(1,N);
W=cumsum(dW);
plot(0:dt:T,[0,W],'r-')
xlabel('t')
ylabel('W(t)')
title('Position over time')
for poisson
function poisson03fig2
clc
fprintf('\nfunction poisson03fig2 OutPut:')
nfig = 0;
K = 10;
KP = 2*K +1; % Include sample of K jumps only.
p = zeros(KP,1);
kstates = 4;
LT = zeros(KP,kstates);
% Begin Calculation:
for kstate = 1:kstates % Test Multiple Simulated Sample Paths:
LT(1,kstate) = 0;
p(1) = 0; % Set initial scaled jump time
% and jump count.
rng(kstate); % Set initial state for repeatability
% or path change.
DTe = -log(rand(K,1)); % Generate random vector of
% K exponential variates.
for k = 1:K % Simulated sample scaled jump times
% LT(k+1) = lambda*T(k+1):
LT(2*k,kstate) = LT(2*k-1,kstate) + DTe(k);
LT(2*k+1,kstate) = LT(2*k,kstate);
p(2*k) = p(2*k-1);
p(2*k+1) = p(2*k-1) + 1;
end
end
% Begin Plot:
nfig = nfig + 1;
scrsize = get(0,'ScreenSize'); % figure spacing for target screen
ss = [5.0,4.0,3.5]; % figure spacing factors
fprintf('\n\nFigure(%i): Simulated Jump Sample Paths\n',nfig)
figure(nfig)
plot(LT(1:KP,1),p,'k-',LT(1:KP,2),p,'k:',LT(1:KP,3),p,'k-.' ...
,LT(1:KP,4),p,'k--','LineWidth',2);
title('Simulated Simple Jump Sample Paths'...
,'FontWeight','Bold','Fontsize',22);
ylabel('P(t), Poisson State'...
,'FontWeight','Bold','Fontsize',22);
xlabel('\lambda t, Scaled Time'...
,'FontWeight','Bold','Fontsize',22);
hlegend=legend('Sample 1','Sample 2','Sample 3','Sample 4'...
,'Location','Southeast');
set(hlegend,'Fontsize',16,'FontWeight','Bold');
set(gca,'Fontsize',16,'FontWeight','Bold','linewidth',3);
set(gcf,'Color','White','Position' ...
,[scrsize(3)/ss(nfig) 60 scrsize(3)*0.60 scrsize(4)*0.80]); %[l,b,w,h]
% End Code
0 Commenti
Risposte (1)
Aditya
il 16 Nov 2023
Hi Maryam,
I understand that you are facing problem in plotting SDE with jump simulations .Here's how you can simulate and plot the SDE with jumps using the given coefficients:
% Set parameters
T = 1;
N = 500;
dt = T / N;
% Simulate Brownian motion
randn('state', 100);
dW = sqrt(dt) * randn(1, N);
W = [0, cumsum(dW)];
% Simulate Poisson process
lambda = 1; % Jump rate
Njumps = poissrnd(lambda * T); % Number of jumps
Tjumps = sort(rand(1, Njumps) * T); % Jump times
% Construct the SDE with jumps
X = W;
for i = 1:Njumps
X = X + (Tjumps(i) <= dt:dt:T) - (Tjumps(i) <= dt:dt:T) .* dt;
end
% Plot the SDE with jumps
t = 0:dt:T;
plot(t, X, 'r-')
xlabel('t')
ylabel('X(t)')
title('SDE with Jumps: X(t) = x + W(t) + \int_{E} N(ds, de)')
In this code, poissrnd(dt, 1, N) generates a random vector of Poisson-distributed jumps with a rate of dt. The jumps are then added to the Brownian motion W to construct the SDE solution X. The resulting process X is plotted against time t.
Note that the code assumes you have the Statistics and Machine Learning Toolbox installed for the poissrnd function, which generates random numbers from a Poisson distribution.
Make sure to adjust the parameters and customize the code as needed for your specific requirements.
Hope this helps.
Thanks and Regards,
Aditya Kaloji
0 Commenti
Vedere anche
Categorie
Scopri di più su Stochastic Differential Equation (SDE) Models 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!