clear, clc, close all


N = 10000;
x = zeros(1,N);
x(1) = 100;

%sigma must be >= 0.
%What variance allows it to trend flat?


EX = 1.1;
VarX = 0.255;

% EX = exp(mu + (sigma^2)/2);
% VarX = (exp(sigma^2) - 1)*exp(2*mu + sigma^2);

mu = log(EX) - 1/2*log(1 + VarX/EX^2)
sigma = sqrt(log(VarX/EX^2 + 1))


for i = 1:length(x)
    x(i+1) = x(i) + log(lognrnd(mu,sigma));
end

% x = lognrnd(mu,sigma,1,N);

% plot(x)

mu_hat = sum(log(x))/length(x);

sigma_hat = sqrt(sum((log(x) - mu_hat).^2)/length(x));