function [ ts, Xt ] = SimulatePricePath(mu, sigma, npoints, T)
% Simulates the price path according to geometric Brownian motion
%
% Input arguments:
% mu - drift, sigma - volatility
% npoints - number of data points to simulate (initial point doesn't count)
% T (default T=1) - simulate on the interval (0..T)
%
% The initial value is assumed to be 1

if (nargin < 4)
    T = 1;
end;

h = T/npoints;
ts = linspace(0,T,npoints+1);

% Brownian path
Bt = [0, cumsum(randn(1,npoints) * sqrt(h))];

% Geometric Brownian path
Xt = exp((mu-sigma.^2/2)*ts + sigma*Bt);

end

