BookmarkSubscribeRSS Feed
Junyong
Pyrite | Level 9

The code below simulates 25 GARCH(1,1) processes with 1,000 observations each and estimates their out-of-sample conditional variances based on GARCH(p,q) with p,q∈{1,2,3} using an expanding window starting from 100 observations.

resetline;
option nodate nonumber ls=128 ps=max;
proc datasets lib=work kill nolist;
run;
data _01;
format I T SIGMA2 U SIGMA21 U1;
call streaminit(1);
do I=1 to 25;
do T=1 to 1000;
if T=1 then do;
SIGMA21=.;
U1=.;
SIGMA2=1;
end;
else SIGMA2=0.1+0.2*U1**2+0.7*SIGMA21;
U=sqrt(SIGMA2)*rand("normal");
output;
SIGMA21=SIGMA2;
U1=U;
end;
end;
run;
%macro REPEAT1;
%do REPEAT=101 %to 1000;
data _99;
T=&REPEAT.;
set _01(rename=(T=T0) where=(T0<=&REPEAT.));
if T0=&REPEAT. then U=.;
run;
proc append base=_98 data=_99;
run;
%end;
%mend;
%REPEAT1;
ods select none;
ods noresults;
proc autoreg;
by T I;
ods output ConvergenceStatus=_96 FitSummary=_97;
model U=/noint garch=(p=1,q=1) maxiter=10000 converge=0.0001;
output out=_95 ht=GARCH11;
model U=/noint garch=(p=1,q=2) maxiter=10000 converge=0.0001;
output out=_94 ht=GARCH12;
model U=/noint garch=(p=1,q=3) maxiter=10000 converge=0.0001;
output out=_93 ht=GARCH13;
model U=/noint garch=(p=2,q=1) maxiter=10000 converge=0.0001;
output out=_92 ht=GARCH21;
model U=/noint garch=(p=2,q=2) maxiter=10000 converge=0.0001;
output out=_91 ht=GARCH22;
model U=/noint garch=(p=2,q=3) maxiter=10000 converge=0.0001;
output out=_90 ht=GARCH23;
model U=/noint garch=(p=3,q=1) maxiter=10000 converge=0.0001;
output out=_89 ht=GARCH31;
model U=/noint garch=(p=3,q=2) maxiter=10000 converge=0.0001;
output out=_88 ht=GARCH32;
model U=/noint garch=(p=3,q=3) maxiter=10000 converge=0.0001;
output out=_87 ht=GARCH33;
run;
ods results;
ods select all;
data _97(keep=T I Model AIC);
set _97(rename=(nValue2=AIC));
where Label2="AIC";
by T I Model;
if last.Model;
run;
proc transpose out=_97(drop=_NAME_) prefix=AIC;
var AIC;
by T I;
run;
proc transpose data=_96 out=_96(drop=_NAME_) prefix=CONV;
var Status;
by T I;
run;
%macro REPEAT2;
%do REPEAT=95 %to 87 %by -1;
proc sort data=_&REPEAT. out=_&REPEAT. nodupkey;
by T I T0;
run;
%end;
%mend;
%REPEAT2;
data _86;
merge _98(where=(T=T0)) _97 _96
_95(where=(T=T0) keep=T I T0 GARCH11)
_94(where=(T=T0) keep=T I T0 GARCH12)
_93(where=(T=T0) keep=T I T0 GARCH13)
_92(where=(T=T0) keep=T I T0 GARCH21)
_91(where=(T=T0) keep=T I T0 GARCH22)
_90(where=(T=T0) keep=T I T0 GARCH23)
_89(where=(T=T0) keep=T I T0 GARCH31)
_88(where=(T=T0) keep=T I T0 GARCH32)
_87(where=(T=T0) keep=T I T0 GARCH33);
by T I;
array AIC(*) AIC1-AIC9;
array CONV(*) CONV1-CONV9;
array GARCHPQ(*) GARCH11--GARCH33;
do J=1 to 9;
if CONV(J)=3 or GARCHPQ(J)=. then AIC(J)=.;
end;
do J=1 to 9;
if AIC(J)=max(of AIC1-AIC9) then GARCH=GARCHPQ(J);
end;
drop T0 J;
run;
quit;

I don't think there exists a logical problem in the code, but AUTOREG aborts at some point generating two warning messages "ERROR: Floating Point Overflow." and "ERROR: Termination due to Floating Point Exception," respectively. Recursive SAS Macro may be one easy solution, but I want to circumvent the way since it's too costly compared to the code above.

1 REPLY 1
ChrisHemedinger
Community Manager

I tried your code and it generates many errors before this exception:

 

ERROR: QUANEW Optimization cannot be completed.
NOTE: Optimization routine cannot improve the function value.
WARNING: Optimization cannot improve the function value.
ERROR: QUANEW Optimization cannot be completed.
NOTE: Optimization routine cannot improve the function value.
WARNING: Optimization cannot improve the function value.
ERROR: QUANEW Optimization cannot be completed.
NOTE: Optimization routine cannot improve the function value.
WARNING: Optimization cannot improve the function value.
ERROR: Floating Point Overflow.
ERROR: Termination due to Floating Point Exception

I don't know enough about this procedure to judge, but usually errors in the log are an indication that there are larger problems.

 

Still, Floating Point Overflow shouldn't happen, so I think you'll need to work with SAS Tech Support to report and maybe find a workaround.

SAS For Dummies 3rd Edition! Check out the new edition, covering SAS 9.4, SAS Viya, and all of the modern ways to use SAS!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 984 views
  • 0 likes
  • 2 in conversation