stocks = hist_stock_data('20122013','31032021','amc','xom')
p1 = stocks(1).AdjClose(1:end);
p2 = stocks(2).AdjClose(1:end);
p4 = stocks(2).Date(1:end);
y1 = diff(log(p1));
y2 = diff(log(p2));
y1 = y1(30:end,:);
y2=y2(30:end,:);
y= [y1 y2];
value= 1000000;
p= 0.01;
SampleSize=length(y2)
TestWindowStart = find(year(p4)==2016,1);
TestWindow = TestWindowStart : SampleSize;
EstimationWindowSize = 500;
pVaR = [0.05 0.01]
Zscore = norminv(pVaR);
Normal95 = zeros(length(TestWindow),1);
Normal99 = zeros(length(TestWindow),1);
for t = TestWindow
i = TestWindow - TestWindowStart + 1
EstimationWindow = t-EstimationWindowSize:t-1;
Sigma = std(y2(EstimationWindow));
Normal95(i) = -Zscore(1)*Sigma;
Normal99(i) = -Zscore(2)*Sigma;
end