2
$\begingroup$

I was going to simulate a geometric brownian motion in matlab, when I recognized that I didnt fully understand the underlying Wiener process. Following the instuctions here I am starting from the form:

enter image description here

Where the $dW_t$ denotes the Wiener process. So $E(dW_t)=0$ and $Var(dW_t) = dt$, right? Could I also write $dW_t = W_{dt}$? Becasue I find the latter more intuitively. So I can simulate $dW_t$ by simulating $X \sim N(0,1)$ and then $dW_t = X\sqrt{dt}$?.

The next step is the discretization of the differential term. So I write: $S_{t+dt} = S_t + S_t \mu dt + S_t \sigma X \sqrt{dt}$

$S_{t+dt} = S_t*(1+ \mu dt + \sigma X \sqrt{dt})$

$S_{t+dt} = S_t*(1+ r_{dt})$

$S_{T} = S_0 *(1+r_1)*(1+r_2)*...*(1+r_T)$

Where $r_{dt}$ means the rate after each time-step. $T$ is the ending time. So I wrote the following matlab-code. Could some one verify this code please?

function [x,y]= brown_data(T, dt,sigma, mu, y0)
x = 0:dt:T;
y = zeros(size(x));
dws = normrnd(0,1,1,numel(x)-1);
tic
ratesPlus1 = [y0 ,1 + mu*dt + sigma*dws*sqrt(dt) ];
y = cumprod(ratesPlus1);
toc
end
$\endgroup$
3
  • 3
    $\begingroup$ These are basic conceptual questions. I suggest you read some books on Brownian motions. $\endgroup$
    – Gordon
    Jul 15, 2015 at 14:06
  • $\begingroup$ Yes, I already read some but I was not sure, so I thought I would find quick help here. And I did :) Anyways.. what book can you recommend? $\endgroup$
    – v.tralala
    Jul 17, 2015 at 11:57
  • $\begingroup$ The good one will be the book "stochastic Calculus for Finance, Vol II" by Shreve. Another good one is the book "stochastic differential equations" by Oksendal $\endgroup$
    – Gordon
    Jul 17, 2015 at 12:40

1 Answer 1

1
$\begingroup$

Your procedure is correct.

However, given that the stock follows a GBM it has a closed form solution, which will yield more accurate results.

$S_{t+\Delta t}=S_te^{(\mu-0.5\sigma^2)\Delta t+\sigma \sqrt{\Delta t}X_{t+\Delta t}}$

Here's a matlab code with the method above:

clear all
% GBM stock price

t = 250;
nsim = 1000;

S = NaN(nsim, t);
Sminus = NaN(nsim, t);


dt = 1/250;

S(:,1) = 100;
mu = 0.08;
sigma = 0.2;
r = 0.08;

epsilon = normrnd(0,1,nsim,t);

% Stock Price Path

for i = 2:250
    S(:,i) = S(:,i-1).*exp((mu-0.5*sigma^2)*dt+sigma*sqrt(dt).*epsilon(:,i));
end
$\endgroup$
1
  • $\begingroup$ Hi, I read in this following thread link that the closed form is better for parallel computing, because I can express $S_t$ in terms of $S_0$. So I modified your code to get rid of the for-loop and used cumprod() again. Given the above variable names I now calculate tic ratesPlus1v2 = [1, exp((mu-sigma^2/2).*dt+ sigma.* dws.*sqrt(dt))]; y2 = y0.* cumprod(ratesPlus1v2); toc But this way the algorithm was slower and I dont understand why the closed form should be more accurate. $\endgroup$
    – v.tralala
    Jul 17, 2015 at 12:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.