Domanda

I am trying to create an SDE model in Matlab with the sde function in the Econometrics toolbox. From looking at the examples on the website, the basic case seems simple enough in that an equation like

dX(t) = 0.1 X(t) dt + 0.3 X(t) dW(t)

can be defined by first creating anonymous functions and then using those in the SDE equation as seen below (where the variables used in the functions are previously defined):

F = @(t,X) 0.1 * X;
G = @(t,X) 0.3 * X;
obj = sde(F, G)    % dX = F(t,X)dt + G(t,X)dW

I was hoping to do something just a bit more complicated in which the drift term of the SDE I would like to model is a function of another SDE. Specifically, the equation is

dY(t) / Y(t) = G(t) dt + sigma dW(t)

Where G(t) is another SDE I've already defined. Would someone be able to give me a sense of what the equation for the drift term (corresponding to F in the code above) would be in this case?

È stato utile?

Soluzione

I don't have the Econometrics toolbox so I can't give you detailed code for it (most Matlab installs don't have this toolbox by default). However, your case is a pretty common so I imagine that it shouldn't be too hard to do what you need. You might consider creating a service request with The MathWorks or posting a question at Quant.StackExchange. Make sure you're clear about the SDEs that you're interested in. Sorry that I can't help you more in that area.

Another way to simulate this coupled set of SDEs is to use my own SDETools toolbox which is available for free on GitHub. These are quite straightforward if you have any experience with Matlab's ODE Suite functions such as ode45. SDETools also has dedicated functions for common stochastic process (e.g., geometric Brownian motion and Ornstein-Uhlenbeck) using their analytic solutions. Here is basic code with arbitrary parameter values to simulate your SDEs using the Euler-Maryama integrator function, sde_euler, in SDETools:

t0 = 0;
dt = 1e-2;
tf = 1e1;
tspan = t0:dt:tf; % Time vector
y0 = [1;1];       % Initial conditions

kappa = 10;
mu = 0;
tau = 1e-1;
sigma = 1e-2;
f = @(t,y)[kappa.*(mu-y(1));y(1).*y(2)]; % Drift
g = @(t,y)[tau;sigma.*y(2)];             % Diffusion

% Set random seed and type of stochastic integration
options = sdeset('RandSeed',1,'SDEType','Ito');

Y = sde_euler(f,g,tspan,y0,options); % Euler-Maruyama
figure;
plot(tspan,Y)

In fact, it's possible that the sde function in the Econometrics toolbox could itself take the two function handles, f and g, I created above.

Here's another way you can simulate the system (it may or may not be faster), this time using the sde_ou function to first generate an OU process, which itself is independent of the other equation:

...

options = sdeset('RandSeed',1);
Y(:,1) = sde_ou(kappa,mu,tau,tspan,y0(1),options); % OU process

f = @(t,y)Y(round(t/dt)+1,1).*y; % Index into OU process as a function of t
g = @(t,y)sigma.*y;
options = sdeset('RandSeed',2,'SDEType','Ito');
Y(:,2) = sde_euler(f,g,tspan,y0(2),options); % Euler-Maruyama of just second equation

figure;
plot(tspan,Y)

Note that even the the same random seed is used for the OU process, the output of Y(:,1) will be slightly different for this and the sde_euler case because of the order in which the Wiener increments are generated internally. Again, you may well be able to do something similar using the function in the Econometrics toolbox.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top