/* We conduct an out-of-sample forecasting test of the efficiency of a simulated ECM model versus a levels VAR of lag length 2 and a independent AR(2) for each series. We want to see how important the cointegrating restrictions are in terms of improving forecasting accuracy over a levels VAR that ignors the restrictions. We also want to see how an incorrectly specified VAR that assumes independence of two AR(2) models for the two series performs relative to the correctly specified ECM model. Here the forecast horizon is h = 3 which should be helpful to the ECM model since we know from Engle and Yoo (1987) that the longer the forecast horizon is, the more forecasting accuracy advantage the ECM offers. */ Options nodate; %macro main(rseed); proc iml; sig = 100*i(2); phi = {-0.2 0.1, 0.5 0.2, 0.8 0.7, -0.4 0.6}; call varmasim(y,phi) sigma = sig n = 100 initial = 0 seed = &rseed; cn = {'y1' 'y2'}; create simul2 from y[colname=cn]; append from y; quit; data simul2; set simul2; t+1; /* Roll the EC model through the hold-out sample data (observations 71 - 100) forecasting three steps ahead each time. */ %macro ecm(num); proc varmax data=simul2(obs=&num) noprint; model y1 y2 / p=2 noint ecm=(rank=1 normalize=y1); output out=result1 lead=3 back=0; run; data result1; set result1; ecmf1 = for1; ecmf2 = for2; if _n_ = &num + 3; keep ecmf1 ecmf2; proc append base=collect1 data=result1; %mend; %macro doit; %do ii=70 %to 97; %ecm(&ii); %end; %mend; %doit; /* Roll the benchmark levels VAR(2) through the hold-out sample data (observations 71 - 100) forecasting three periods ahead each time. */ %macro var(num); proc varmax data=simul2(obs=&num) noprint; model y1 y2 / p=2 noint; output out=result2 lead=3 back=0; run; data result2; set result2; varf1 = for1; varf2 = for2; if _n_ = &num + 3; keep varf1 varf2; proc append base=collect2 data=result2; %mend; %macro doit2; %do ii=70 %to 97; %var(&ii); %end; %mend; %doit2; /* Roll the two independent AR(2) models through the hold-out sample data (observations 71 - 100) forecasting three periods ahead each time. */ %macro Ar2(num); proc varmax data=simul2(obs=&num) noprint; model y1 y2 / p=2 noint; restrict AR(1,1,2)=0, AR(1,2,1)=0, AR(2,1,2)=0, AR(2,2,1)=0; output out=result3 lead=3 back=0 noprint; run; data result3; set result3; ar2f1 = for1; ar2f2 = for2; if _n_ = &num + 3; keep ar2f1 ar2f2; proc append base=collect3 data=result3; %mend; %macro doit3; %do ii=70 %to 97; %Ar2(&ii); %end; %mend; %doit3; data actual; set simul2; if 72 < _n_; actualy1 = y1; actualy2 = y2; keep actualy1 actualy2; data compare; merge actual collect1 collect2 collect3; keep actualy1 actualy2 ecmf1 ecmf2 varf1 varf2 ar2f1 ar2f2; data errors; set compare; ecme1 = actualy1 - ecmf1; ecme2 = actualy2 - ecmf2; vare1 = actualy1 - varf1; vare2 = actualy2 - varf2; ar2e1 = actualy1 - ar2f1; ar2e2 = actualy2 - ar2f2; absecme1 = abs(ecme1); absecme2 = abs(ecme2); absvare1 = abs(vare1); absvare2 = abs(vare2); absar2e1 = abs(ar2e1); absar2e2 = abs(ar2e2); ecme12 = ecme1**2.0; ecme22 = ecme2**2.0; vare12 = vare1**2.0; vare22 = vare2**2.0; ar2e12 = ar2e1**2.0; ar2e22 = ar2e2**2.0; /* Calculate the MAEs and MSEs of the Competing Models. */ proc univariate data=errors noprint; var absecme1 absvare1 absar2e1 absecme2 absvare2 absar2e2 ecme12 vare12 ar2e12 ecme22 vare22 ar2e22; output mean = maeecm1 maevar1 maear21 maeecm2 maevar2 maear22 mseecm1 msevar1 msear21 mseecm2 msevar2 msear22 out = results; run; proc append base=collect4 data=results; run; /* delete DATA SETS collect1, collect 2, and collect3 */ proc datasets lib=work mt=data nolist; delete collect1 collect2 collect3; run; %mend; /* end of main macro */ %macro doit4; %do i=1 %to 10; %main(45876+&i); %end; %mend; %doit4; /* Print the Forecasting Accuracies of the the Competing Methods */ proc print data=collect4; var maeecm1 maevar1 maear21 maeecm2 maevar2 maear22 mseecm1 msevar1 msear21 mseecm2 msevar2 msear22; title 'Forecasting Accuracy Measures of Competing Methods'; title2 'Forecast Horizon = 3'; run; data count; set collect4; if maeecm1 < maevar1 and maeecm1 < maear21 then maeecm1c = 1; else maeecm1c = 0; if maevar1 < maeecm1 and maevar1 < maear21 then maevar1c = 1; else maevar1c = 0; if maear21 < maeecm1 and maear21 < maevar1 then maear21c = 1; else maear21c = 0; if mseecm1 < msevar1 and mseecm1 < msear21 then mseecm1c = 1; else mseecm1c = 0; if msevar1 < mseecm1 and msevar1 < msear21 then msevar1c = 1; else msevar1c = 0; if msear21 < mseecm1 and msear21 < msevar1 then msear21c = 1; else msear21c = 0; if maeecm2 < maevar2 and maeecm2 < maear22 then maeecm2c = 1; else maeecm2c = 0; if maevar2 < maeecm2 and maevar2 < maear22 then maevar2c = 1; else maevar2c = 0; if maear22 < maeecm2 and maear22 < maevar2 then maear22c = 1; else maear22c = 0; if mseecm2 < msevar2 and mseecm2 < msear22 then mseecm2c = 1; else mseecm2c = 0; if msevar2 < mseecm2 and msevar2 < msear22 then msevar2c = 1; else msevar2c = 0; if msear22 < mseecm2 and msear22 < msevar2 then msear22c = 1; else msear22c = 0; proc print data = count; run; /* Calculate the average performances of the Competing Models. */ proc univariate data=count noprint; var maeecm1c maevar1c maear21c maeecm2c maevar2c maear22c mseecm1c msevar1c msear21c mseecm2c msevar2c msear22c; output mean = maeecm1p maevar1p maear21p maeecm2p maevar2p maear22p mseecm1p msevar1p msear21p mseecm2p msevar2p msear22p out = results; run; title 'Proportion of Wins for each method and given variable and measure'; title2 'Forecast Horizon is h=3'; proc print data = results; run;