Matlab → Simulation → Brownian Motion → Stock Price
The stock price following geometric Brownian motion is given by
This is geometric Brownian motion stochastic differential equation, and the discrete-time version of the equation is
So, the change in stock price from time 0 to is given by
Stock price simulation in Matlab
t=1; n=500; dt=t/n;
x=0:dt:t;
dz=sqrt(dt)*randn(1,n);
s=15; %Initial stock price
mu=0.1; sigma=0.3;
ds=mu*s*dt+sigma*s*dz;
st=s+cumsum(ds);
plot(x,[s,st])
In the next example, stock prices are simulated in Matlab with different and when the stock prices are assumed to follow geometric Brownian motion stochastic differential equation.
Stock price simulation using different mu and sigma
t=1; n=500; dt=t/n;
x=0:dt:t;
dz=sqrt(dt)*randn(1,n);
s=20; %Initial stock price
mu1=0.1; sigma1=0.2;
mu2=0.2; sigma2=0.3;
mu3=0.3; sigma3=0.45;
ds1=mu1*s*dt+sigma1*s*dz;
ds2=mu2*s*dt+sigma2*s*dz;
ds3=mu3*s*dt+sigma3*s*dz;
st1=s+cumsum(ds1); st2=s+cumsum(ds2); st3=s+cumsum(ds3);
plot(x,[s,st1],'r',x,[s,st2],'g',x,[s,st3],'b')