% Matlab program file to accompany
% Christoffersen and Diebold (1997),
% "Cointegration and Long-Horizon Forecasting"
% This file plots population and simulation 
% results from the simple example.
% exsim.m must be run first to generate exsim.mat.
% Scroll through the figures by hitting any key.

clear;
clf;

% Get results from exsim.m stored in exsim.mat
% --------------------------------------------
load exsim;
x=[1:h]';
q=sig2e/sig2v;

% True theta 
% ----------
thtru=.5*(sqrt(lam^4*q^2+4*lam^2*q)-lam^2*q-2);  
  
% trace MSE of system vs univariate in population 
% -----------------------------------------------
trtrum=(q*x+lam^2*q*x+2+thtru)./(q*x+1+lam^2*x*q); 

% trace MSEtri of system vs univariate in population
% --------------------------------------------------
trtrtr=ones(h,1)*(1+(2+thtru)*q)/(1+q);            

% trace MSE uni in population
reset(gcf);
plot(x,trtrum,'r-');
xlabel('          Forecast Horizon');
ylabel('Trace MSE Ratio');
title('Figure 1. Univariate vs. System MSE');
axis([1 50 1 1.4]);
print -dmeta;
pause;

% trace MSEtri uni in population
reset(gcf);
plot(x,trtrtr,'r-');
xlabel('          Forecast Horizon');
ylabel('Trace MSEtri Ratio');
title('Figure 2. Univariate vs. System MSEtri');
axis([1 50 1 1.4]);
print -dmeta;
pause;

%trace MSE uni and trace MSEtri uni simulated
reset(gcf);
plot(x,truni'./ttreg','r-',x,trttuni'./trtteg','r-');
xlabel('          Forecast Horizon');
ylabel('Relative Accuracy');
axis([1 50 1 1.4]);
title('Figure 3. Estimated Univariate vs. System MSE and MSEtri');
text(25,1.28,'Trace MSEtri');
text(17,1.04,'Trace MSE');
print -dmeta;
pause;

% trace MSE UVAR simulated
reset(gcf);
plot(x,truv'./ttreg','r-');
xlabel('          Forecast Horizon');
ylabel('Trace MSE Ratio');
title('Figure 4. Estimated Levels VAR vs. System MSE');
axis([1 50 1 2.5]);
print -dmeta;
pause;

% trace MSE DVAR simulated
reset(gcf);
plot(x,trdv'./ttreg','r-');
xlabel('          Forecast Horizon');
ylabel('Trace MSE Ratio');
axis([1 50 1 1.4]);
title('Figure 5. Estimated DVAR vs. System MSE');
print -dmeta;
pause;

% trace MSEtri DVAR simulated
reset(gcf);
plot(x,trttdv'./trtteg','r-');
xlabel('          Forecast Horizon');
ylabel('Trace MSEtri Ratio');
axis([1 50 1 1.4]);
title('Figure 6. Estimated DVAR vs. System MSEtri');
print -dmeta;