# Matlab implementation for modelling stock price process

I am trying to model the stock's price process. Let's assume volatility and risk-free rate is given. I've come up with the code below to try and model the price process with the geometrical Brownian motion. This should take into account risk-free rate and dividend yield q.

$$S_t = S_0 \exp\left(\left[r-q-\frac 12\sigma^2\right]t + \sigma W_t\right)$$

% initial price, time, risk-free rate, dividend yield pct, volatility
% p = simPrice(66, 365, 0.0088, 0.0236, 0.2);

function [path] = simPrice(initialPrice, days, r, q, sigma)

path = zeros(1, days+1);
path(1) = initialPrice;
for t=1:length(path)-1
path(t+1) = nextSt(path(t), (1/days), r, q, sigma);
end

end

function [ expected ] = nextSt(initial, t, r, q, sigma)

n = randn();
expected = initial * exp( (r - q -(0.5 * (sigma^2)))*t + sigma*sqrt(t)*n);
end


However, as I am quite new to this, I'd like some reassurance that this is indeed correct. I feel like the price process is a bit jumpy? I am particularly worried that I am doing something wrong in the nextSt(..) function. This could be either in the formula inside the function itself (am I implementing the $W_t$ part of the formula correctly?) or the parameters I pass to it. For example, I am not sure if I am doing the time parameters right here. Note that I am using annualised volatility, dividend yield and risk-free rate. The next St is always computed over one day. So shouldn't I have to convert those parameters to daily values by dividing by $sqrt(252)$?

This is the result when I do so: The results on the first graph seem more plausible, but the parameters I used there make no sense?

• There is no jump in your simulation. Black Scholes model has no jump term. However, it is fine. – user16651 Dec 25 '16 at 6:33
• @BehrouzMaleki But I don't get how I can compute the next day St, with an annualised volatility, dividend and risk-free rate. If I convert those parameters to daily parameters by dividing by $sqrt(252)$ the paths have virtually no variance anymore – xrdty Dec 25 '16 at 14:53
• Sorry I didn't understand what you said. – user16651 Dec 25 '16 at 14:56
• @BehrouzMaleki I updated my question below the first graph. So I am always computing next day's price of the stock. But the parameters I use for the brownian motion function are annualised. So I give a sigma that is 0.2 over a year. But I am working with periods of a day. This does not make sense right? – xrdty Dec 25 '16 at 15:00
• Note , you should calibrate the model. You can't use arbitrary parameters and say the result is meaningless. – user16651 Dec 25 '16 at 15:07