I am working on a project to approximate numerically the solution $X_t$ of a stochastic differential equation (SDE) using the Euler method. I have do to this for the Brownian motion with drift. I am asked to stimulate $N$ paths under both the P and Q measure on the interval $[0,T]$. The pseudo code is as follows:
for i to N-1
- calculate the drift as function of previous stock price ($\mu$)
- calculate the volatility as function of previous stock price ($\sigma$)
- draw innovation from standard normal distribution ($\epsilon$)
- $S_{t+i} = S_t + \mu_t dt + \sigma_t \sqrt{dt } \epsilon_t$. next
where $dt$ is defined as $(T-0)/N$.
My current code is as follows:
nr_runs = 1000; %number of simulation runs
N = 1000; %compute N grid points
t0 = 0;
T = 10;
dt = (T - t0) / N;
x0 = 0; %starting point
x = zeros(1000);
mu = 0;
sigma = zeros(1000);
for i = 1:N
sigma(i) = sqrt(i*dt); %under P measure, variance equal to time
epsilon = normrnd(0,1);
if i == 1
x(i) = x0 + mu*dt + sigma(i)* sqrt(dt)*epsilon;
else
x(i+1) = x(i) + mu*dt + sigma(i)* sqrt(dt)*epsilon;
end
end
M = mean(x);
However, I know no idea how to calculate the drift ($\mu$) from the previous stock price. What is the formula?
Thank you! Any help is appreciated.