Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Forecasting
- /
- Recursive estimation of conditional variance using a GARCH(1,1) model

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 04-25-2014 08:42 AM
(1666 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Stay tuned. -Ken

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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= ®n %to &totn %by 1;

* what is the first obs? ;

data _null_;

x=&i - ®n +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;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Dear Ken,

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

Best regards,

Wouter van Benthem

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.