% Simulation of NASDAQ data using
% random numbers generated from
% a normal fit of the log returns.

load SNindices

plot(N)
hold on

i = 2:length(dates);
logNreturn = log(N(i)./N(i-1));  % = log(Nreturn + 1) appx.= Nreturn = [N(i) - N(i-1)]/N(i-1)
[mu, sigma] = normfit(logNreturn);

simreturns = normrnd(mu, sigma, [1 length(i)]);

simN = zeros(size(N));
simN(1) = N(1);
for t = 2:length(dates)
    simN(t) = simN(t-1)*(simreturns(t-1) + 1); % Solve logNreturn appx.= [N(i) - N(i-1)]/N(i-1) for N(i)
end

plot(simN, 'g')
legend('NASDAQ Data', 'Simulation')