function St = brownian(N)

%N is number of data points.

%This generate might not be perfect, but it's quite good IMO.
%I suppose eventually a better one will be made - Matt.


St = zeros(1,N);
S0 = 30;
St(1) = S0;

sigma = 0.30;

r = 0.05; %yearly interest rate
dt = 1/365;
rdt = (1 + r)^dt - 1; %interest rate for the selected dt.
mu = 1 + rdt;
Wt = zeros(1,N);

for i = 1:N-1
    
    Wt(i) = randn;
    
    St(i+1) = St(i)*(mu + sigma*sqrt(dt)*Wt(i)); %i'm not sure why dt is sqrt.
    %the square root of time is because of variance is sigma^2*dt. So
    %square of that is sigma*sqrt(dt). 
    
%     St(i+1) = St(i)*exp((mu - (sigma^2)/2)*dt    + sigma*St(i)*sqrt(dt)*Wt(i));
%     Can't get this one to work
end

% movement = diff(St);

% EX = exp(mu + (sigma^2)/2);
% VarX = (exp(sigma^2) - 1)*exp(2*mu + sigma^2);
        
% mu_hat = sum(movement)/length(movement);
% s2 = (1/N)*sum((movement - mu_hat).^2);
% sigma_hat = sqrt((N/(N-1))*s2);










