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
Best Answer
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.