% test garch11.m


n = 5000;
n0 = 500;
m = n+n0;

c = 0.02; a = 0.05; b = 0.92;

eps = randn(m,1);

sigma2 = zeros(m,1);
sigma2(1) = c/(1-a-b);
w = zeros(m,1);
for i=2:m
    sigma2(i) = c + a*w(i-1)^2 + b * sigma2(i-1);
    w(i) = sqrt(sigma2(i)) * eps(i);
end

x = w(n0+1:m);

%return;

theta0 = [c a b]';
order = [1 1]';

%profile on;
fit = garch(x);

V = inv(fit.Hessian);
se = sqrt(diag(V));

fprintf('c:\t %f (%f)\n', fit.c1, se(1));
fprintf('b:\t %f (%f)\n', fit.arch, se(2));
fprintf('a:\t %f (%f)\n', fit.garch, se(3));

[H, pValue, Qstat] = lbqtest(fit.residuals);
disp('Ljung-Box test for standardized residuals:')
disp('Statistic P-value ')
disp([Qstat pValue])
[H, pValue, Qstat] = lbqtest(fit.residuals.^2);
disp('Ljung-Box test for squared standardized residuals:')
disp('Statistic P-value ')
disp([Qstat pValue])

figure(1)
subplot(211), plot(fit.residuals)
subplot(212), plot(fit.sigma)
%figure(1), plot(u)
    
%profile viewer
