BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Junyong
Pyrite | Level 9

The current post relocates the previous post. The following code (1) downloads McDonald's stock prices from July 5, 1966 to November 1, 2021, (2) computes its percent returns, and (3) estimates the GARCH(1,1) model.

/*-----------------------------------------------------------------------------+
| set filename using url=ticker, period1=start, period2=end                    |
+-----------------------------------------------------------------------------*/
%let url=https://query1.finance.yahoo.com/v7/finance/download/mcd;
%let period1=%sysevalf('5jul1966:0:0:0'dt-3653*24*60*60);
%let period2=%sysevalf('1nov2021:23:59:59'dt-3653*24*60*60);
filename mcd url "&url?period1=&period1%str(&)period2=&period2";

/*-----------------------------------------------------------------------------+
| download daily mcdonalds data from yahoo                                     |
+-----------------------------------------------------------------------------*/
proc import file=mcd dbms=csv replace out=mcd;
run;

/*-----------------------------------------------------------------------------+
| compute returns using prices                                                 |
+-----------------------------------------------------------------------------*/
proc expand out=mcd;
	id date;
	convert adj_close=return/tout=(pctdif);
run;

/*-----------------------------------------------------------------------------+
| run garch(1,1) using autoreg                                                 |
+------------------------------------------------------------------------------+
| the results are r(t)=0.0832+e(t) and                                         |
| h(t)=0.009160+0.0485*e(t)^2+0.9539*h(t-1)                                    |
| as ARCH1+GARCH1=0.0485+0.9539=1.0024>1, there is no unconditional variance   |
+------------------------------------------------------------------------------+
| however, sas assigns h(1)=3.8592544106 to the jul 6, 1966 observation        |
| where does this number come from? this is not ARCH0/(1-ARCH1-GARCH1)!        |
+-----------------------------------------------------------------------------*/
proc autoreg;
	model return=/garch=(q=1,p=1);
	output ht=variance out=mcd;
run;

Because ARCH1+GARCH1=0.0485+0.9539=1.0024>1, the unconditional variance is undefined. However, the output data set assigns 3.8592488163 as the variance of the first observation—how does AUTOREG compute this value of 3.8592488163 here? It seems this is not documented in The AUTOREG Procedure.

1 ACCEPTED SOLUTION

Accepted Solutions
SASCom1
SAS Employee

I did not find a specific reference. Hamilton(1996) shows that Bollerslev(1986) suggested using the sample analogue, 1/T*sum of e^2_t to initialize both e^2_0 and h_0. Different software packages may use slightly different initializations. The initialization used in AUTOREG is based on the assumption that E(h_t) = h_0, and E(e^2_t) = mse: 

 

h_t = arch0 + arch1*e^2_t-1 + garch1*h_t-1 

 

E(h_t) = arch0 + arch1*E(e^2_t-1) + garch1*E(h_t-1)

 

since E(h_t) = E(h_t-1), 

 

E(h_t) = [arch0 + arch1*E(e^2_t-1)]/(1-garch1)

 

assuming E(e^2_t-1) = mse, then

 

h_0 = (arch0 + arch1*mse)/(1-garch1)

 

The initialization is not currently discussed in the PROC AUTOREG documentation, but we will include this information in the future. 

View solution in original post

3 REPLIES 3
SASCom1
SAS Employee

Hello,

 

The formula for h_t in GARCH(1,1) model is:

 

h_t = arch0 + arch1*e_t-1**2 + garch1*h_t-1       

 

at t = 1, you need initial value for e_0^2 and h_0 in the above formula to compute h_1. In PROC AUTOREG, e_0^2 is initialized using the _mse_ obtained from the corresponding model without GARCH, and h_0 is initialized using  (arch0+arch1*_mse_)/(1-garch1). You then substitute these values into the formula for h_1.

 

Following is an example illustrating computation of the first observation for h_t in GARCH model:

 

data one ;
lu = 2.5 ;
lh = 2.5 ;
 do i = -500 to 1000;
  h = 0.1 + 0.2*lu**2 + 0.5*lh ;
  u = sqrt(h)*rannor(12345);
   y = .5 + u;
   lu = u ;
   lh = h ;
   if i > 0 then output;
 end;
run;


/*estimate garch(1,1) model */
proc autoreg data=one outest = est;
  model y = / garch=(q=1,p=1);
  output out=out cev=cev ;
run;

proc print data = est;  run;

/*estimate model without garch effects*/
/*mse from this model is used to initialize e_0^2 in the formula for h_1 */
proc autoreg data=one outest=est1;
  model y =  / noprint ;
run;


proc print data = est1 ; run ;


data null ;
set est1 ;
call symput('mse',_mse_) ;
run;

data compt ;
set est ; set out ;
/* formula for  h_1 = arch0 + arch1*e_0^2 + garch1*h_0 
   e_0^2 is initialized using _mse_ from the model without garch;
   h_0 is initialized using (_ah_0 + _ah_1*_mse_)/(1-_gh_1)  */
 h_1 = _ah_0 + _ah_1*&mse + _gh_1*(_ah_0 + _ah_1*&mse)/(1-_gh_1);
 diff = h_1 - cev ;
run;

proc print data = compt ;
var h_1 cev diff;
run;

Hope this helps.

Junyong
Pyrite | Level 9

So it seems ε02=OLS MSE and h0=(ARCH0+ARCH1*MSE)/(1-GARCH0) in autoreg.

%let url=https://query1.finance.yahoo.com/v7/finance/download/mcd;
%let period1=%sysevalf('5jul1966:0:0:0'dt-3653*24*60*60);
%let period2=%sysevalf('1nov2021:23:59:59'dt-3653*24*60*60);
filename mcd url "&url?period1=&period1%str(&)period2=&period2";

proc import file=mcd dbms=csv replace out=mcd;
run;

proc expand out=mcd;
	id date;
	convert adj_close=return/tout=(pctdif);
run;

ods select none;
ods results=off;

proc autoreg;
	model return=/garch=(q=1,p=1);
	output ht=variance out=mcd;
	ods output fitsummary=fit parameterestimates=para;
run;

ods results=on;
ods select all;

data _null_;
	set fit;
	if _n_=2 then call symput('mse',nvalue1);
run;

data _null_;
	set para;
	if _n_=3 then call symput('arch0',estimate);
	else if _n_=4 then call symput('arch1',estimate);
	else if _n_=5 then call symput('garch1',estimate);
run;

data _null_;
	set mcd;
	if _n_=2 then call symput('variance',variance);
run;

%put %sysevalf((&arch0+&arch1*&mse)/(1-&garch1));
%put &variance;

(1) Is there a reference for the formulation used for h0? (2) Is this stated in the guide?

SASCom1
SAS Employee

I did not find a specific reference. Hamilton(1996) shows that Bollerslev(1986) suggested using the sample analogue, 1/T*sum of e^2_t to initialize both e^2_0 and h_0. Different software packages may use slightly different initializations. The initialization used in AUTOREG is based on the assumption that E(h_t) = h_0, and E(e^2_t) = mse: 

 

h_t = arch0 + arch1*e^2_t-1 + garch1*h_t-1 

 

E(h_t) = arch0 + arch1*E(e^2_t-1) + garch1*E(h_t-1)

 

since E(h_t) = E(h_t-1), 

 

E(h_t) = [arch0 + arch1*E(e^2_t-1)]/(1-garch1)

 

assuming E(e^2_t-1) = mse, then

 

h_0 = (arch0 + arch1*mse)/(1-garch1)

 

The initialization is not currently discussed in the PROC AUTOREG documentation, but we will include this information in the future. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 372 views
  • 1 like
  • 2 in conversation