BookmarkSubscribeRSS Feed
WvanBenthem88
Calcite | Level 5

Dear all,

Im trying to improve an old program written by one of my predecessors. The program takes 15 minutes to complete. Assuming there was some efficiency to be won I started my own program with the intention to produce the same results.

From what I read in the code it appears a Garch(1,1) is estimated for every period in time from the data set.

This is done using the following code:

%MACRO estimfx(lastobs=);  
%do X=261 %to &Lastobs. ;

      data temp; set FX_M;
            if &x-259<=seq<=&x;
      run;

      proc autoreg data=temp noprint;
            model ret_eur = / garch=(q=1,p=1,type=stationary) maxiter=200;
               output out=temp cev=vhat;
         quit;

         data temp_A; set temp;
               adj=1;
      run;

    data temp_S; set temp;
          keep seq;
      run;

    proc means data=temp_S noprint;
          var seq ;
          output out=s_max max=Seq_M;
      run;

    data s_max; set s_max;
          adj=1;
      run;

    data temp_A;
            merge       s_max
                        temp_A;
            by adj;
          drop _type_ _freq_;
      run;

    data temp_A; set temp_A;
          if seq=seq_M;
      run;

      PROC APPEND BASE = fxconvar DATA = temp_A;
%end;
%mend estimfx;

It appears to me that if there are 4000 observations, the garch-model will be estimated at every point in the time series (about 4000 times). This takes quite a while. So my question is, isn't there some option out there to yield the same result without looping over every point in time? (FYI seq = _n_)

Best regards,

Wouter

3 REPLIES 3
ets_kps
SAS Employee

Hi Wouter,

So far I think you have made good use of MACRO and there really isn't anything you could do to speed that part up (the passes).  The developer and I have talked about this issue and one idea is to set the most recent estimates as INITIAL values on the next window of parameters.  This could really speed things up.  We are working some code that would let you do this. 

If you have some ideas on how to do that, you can specify the values with this code

SAS/ETS(R) 13.1 User's Guide

Stay tuned. -Ken

ets_kps
SAS Employee

Here is the code to do your rolling window estimation but with the added enhancement that your initial starting values are based upon the previously estimated model.  I would think that this would speed up estimation considerably.

SAS Technical support was instrumental in creating this code and should be given full credit.  It is a shining example of the skill of our technical support. -Ken

/*************************************

* generate some data;

data a ;

do i = 1 to 100 ;

x = normal(1) ;

y = 2+3*x + rannor(23);

output;

end;

run;

%rolling(data=a , outest=est1 ,regn=20 ,totn=45  );

proc print data= est1; run;

**************************************/

%macro rolling(data= , outest= ,regn= ,totn=  );

* this macro will perform the rolling regressions;

* each rolling regression uses estimates from previous rolling window as initial values ;

* first rolling window uses estimates using all observations as initial values ;

*     data=     data set name;

*   outest=     OUTEST= data set;

*     regn=     number of obs in each regression;

*     totn=     number of obs in the data set;

* clear out the OUTEST= data set;

proc datasets lib=work;

delete &outest;

run;

/*use outest from all observations as initial values for the first rolling window*/

proc autoreg data = a outest = _temp_ noprint;

model y =x /nlag= 2 garch=(p=1,q=1);

run;

%do i= &regn %to &totn %by 1;

* what is the first obs?  ;

data _null_;

x=&i - &regn +1;

call symput('start',trim(left(x)));

data _null_;

lab='r'||trim(left(&start))||'_'||trim(left(&i));

call symput('label',lab);

run;

data null ;

set _temp_;

call symput('int',Intercept);

call symput('beta',x);

call symput('ar1',_A_1);

call symput('ar2',_A_2);

call symput('arch0',_AH_0);

call symput('arch1',_AH_1);

call symput('garch1',_GH_1);

run;

* run the regression;

proc autoreg data=&data(firstobs=&start obs=&i) outest=_temp_ noprint plots = none;

&label: model y=x /nlag= 2 garch=(p=1,q=1) initial = (&int &beta &ar1 &ar2 &arch0 &arch1 &garch1);

run;

* append the OUTEST= data set;

proc append base=&outest data=_temp_;

%end;

%mend;

* generate some data;

data a ;

do i = 1 to 100 ;

x = normal(1) ;

y = 2+3*x + rannor(23);

output;

end;

run;

%rolling(data=a , outest=est1 ,regn=20 ,totn=45  );

proc print data= est1; run;

WvanBenthem88
Calcite | Level 5

Dear Ken,

I appreciate your elaborate asnwer and the time you have put in to this Smiley Happy Will try to implement your code right away! And I will get back on the results.

Best regards,


Wouter van Benthem

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1733 views
  • 1 like
  • 2 in conversation