Matlab Code to simulate trajectories of Ito process.

4k Views Asked by At

I need some help to generate a Matlab code in order to do the following question. Can somebody help me in this regard. Any sort of hint that could be helpful will surely be appreciated..

Q: "Simulate $N=25$ trajectories of the Ito Process X satisfying the following SDE

$dXt = \mu X_tdt + \sigma X_tdB_t.$

with $X_0=1$, $\mu=1.5$, $\sigma=1.0$ and their Euler approximations with equidistant time steps of size $\Delta=2^{-4}$ corresponding to the same sample paths of the Wiener process on the time interval $[0,T]$ for $T=1$. Evaluate the absolute error by the statistic defined below

m=$\frac1N$$\sum_{k=0}^N $|$X_{T,k}$-$Y_{T,k}$|

where $X_{T,k}$ and $Y_{T,k}$ respectively are the $k$-th simulated trajectories of Ito process and their Euler approximation corresponding to same sample paths of the Wiener process"

I have created the following code on Matlab for the above question. Can somebody correct me if I'm wrong somewhere.

randn('state',100)

mu=1.5; sigma=1; Xzero=1;

T=1; N=25; dt=T/N;

dW=sqrt(dt)*randn(1,N);

W=cumsum(dW);

Xtrue=Xzero*exp((mu-0.5*sigma^2)*([dt:dt:T])+sigma*W);

Xem=zeros(1,N);

Xem(1)=Xzero+dt*mu*Xzero+mu*Xzero*dW(1);

for j=2:N

Xem(j)=Xem(j-1)+dt*mu*Xem(j-1)+sigma*Xem(j)*dW(j);

end

2

There are 2 best solutions below

4
On

The increment of Brownian motion $B_{t+ \Delta }- B_t$ is normally distributed with mean $0$ and standard deviation $\sqrt{\Delta}.$

Generate a sample path using the discrete Euler approximation:

$$X_{k+1}=X_{k} + \mu X_k \Delta + \sigma X_k\sqrt{\Delta}\xi\,\,(k=1,2,...),$$

where $\xi$ is a random number with a standard normal distribution.

To generate random samples for $\xi$, first generate a uniformly distributed random number $r \sim$ U(0,1) and take $\xi = N^{-1}(r)$ where $N$ is the standard normal distribution function.

10
On

Your stochastic differential equation is for geometric Brownian motion. Using your notation, the analytic solution for geometric Brownian motion under Itō's interpretation is

$$X_t = X_0\space\text{exp}\left(\left(\mu-\frac{\sigma^2}{2}\right)t + \sigma B_t\right)$$

This is not what you're using in your Matlab code for Xtrue.

To simulate your system, you can use the Euler-Maruyama for Itō SDEs. @RLL describes this very well so I won't repeat it here. Your Matlab code, however, doesn't appear to implement Euler-Maruyama correctly. There's a mystery parameter lambda, the parameter sigma is missing, and the mu parameter is used in diffusion part rather than the drift. As this appears to be an assignment and I think you're capable fixing this, I'll leave the rest to you.

For further details on SDEs, Brownian motion, and simulating them with Matlab I recommend this excellent paper:

Desmond J. Higham, 2001, An Algorithmic Introduction to Numerical Simulation of Stochastic Differential Equations, SIAM Rev. (Educ. Sect.), 43 525–46. http://dx.doi.org/10.1137/S0036144500378302 http://www.caam.rice.edu/~cox/stoch/dhigham.pdf

The URL to the Matlab files in the paper won't work, use this one: https://www.maths.ed.ac.uk/~dhigham/algfiles.html

(Note that the Matlab code used is 13 years old now not meant for efficiency. Some things have changed since, e.g., how to set the random seed.)