Panel Garch: coding general mean and conditional varian

Discussions of ARCH, GARCH, and related models

Panel Garch: coding general mean and conditional varian

Postby trish » Fri Apr 06, 2012 3:41 am

CAN YOU HELP PLEASE I AM A NEW USER. I AM USING THE ESTIMA PANEL GARCH (1,1) EXAMPLE WITH THEIR XRATE DATA (FOR CONVENIENCE TO GET CODING CORRECT). I WILL EVENTUALLY APPLY TO A LARGER PANEL OF RETURNS WITH MORE DUMMIES AND POSSIBLY MORE AR TERMS. TO START I HAVE INCORPORATED ONE DUMMY AND ONE AR(1) TERM INTO THE MEAN EQUATION.
I NOW WISH TO ADD THE DUMMY VARIABLE TO THE VARIANCE EQU TO GET ITS OVERALL EFFECT ON THE CONDITIONAL VARIANCE OF THE PANEL. ALSO MAY WISH TO ADD FURTHER LAGGED VALUES OF UU TO THE CONDITIONAL VARIANCE. I ATTACH THE PRG BELOW. THANK YOU IN ADVANCE.

Code: Select all
all 6237
    open data g10xrate.xls
    data(format=xls,org=columns) / usxjpn usxfra usxsui
*Bring in  dummy, say E.G. at obs 3000. Note that this is an identical dummy applied to each i in the panel

   dummy(ao=3000) dumann1 /
   dummy(ao=3000) dumann2 /
   dummy(ao=3000) dumann3 /
   *print / dumann1
    *
    set xjpn = 100.0*log(usxjpn/usxjpn{1})
    set xfra = 100.0*log(usxfra/usxfra{1})
    set xsui = 100.0*log(usxsui/usxsui{1})
    *
    * Estimation using MAXIMIZE
    * The initial few lines of this set the estimation range, which needs to
    * be done explicitly, and the number of variables. Then, vectors for the
    * dependent variables, residuals and residuals formulas are set up. The
    * SET instructions copy the dependent variables over into the slots in
    * the vector of series.
    *
    compute gstart=3,gend=6237
    compute n=3
    dec vect[series] y(n) u(n) yl1(n) dumann(n)
    dec vect[frml] resid(n)
    set y(1) = xjpn
    set y(2) = xfra
    set y(3) = xsui
    set yl1(1) = xjpn{1}
   set yl1(2) = xfra{1}
   set yl1(3) = xsui{1}
   set dumann(1) = dumann1
   set dumann(2) = dumann2
   set dumann(3) = dumann3
    *
    * This is specific to a mean-only model. It sets up the formulas (the &i
    * are needed in the formula definitions when the FRML is defined in a
    * loop), and estimates them using NLSYSTEM. This both initializes the
    * mean parameters, and computes the unconditional covariance matrix. If
    * you want more general mean equations, the simplest way to do that
    * would be to define each FRML separately.
    *
   dec vect b(n) ar(n) d(n)
   
   * Do it first with separate frms's
   *nonlin(parmset=meanparms) b1 b2 b3 ar1 ar2 ar3 d1 d2 d3
   *frml resid(1) = y(1)-b1-ar1*yl1(1)-d1*dumann(1)
   *frml resid(2) = y(2)-b2-ar2*yl1(2)-d2*dumann(2)
   *frml resid(3) = y(3)-b3-ar3*yl1(3)-d3*dumann(3)
   
   * Now do it in a loop to see if identical to above
   nonlin(parmset=meanparms) b ar d
    do i=1,n
       frml resid(i) = (y(&i)-b(&i)-ar(&i)*yl1(&i)-d(&i)*dumann(&i))
    end do i
    nlsystem(parmset=meanparms,resids=u) gstart gend resid
    compute rr=%sigma
   display rr

    *
    * The paths of the covariance matrices and uu' are saved in the
    * SERIES[SYMM] names H and UU. UX and HX are used to pull in residuals
    * and H matrices.
    *
    declare series[symm] h uu
    *
    * ux is used when extracting a u vector
    *
    declare symm hx(n,n)
    declare vect ux(n)
    *
    * These are used to initialize pre-sample variances.
    *
    gset h  * gend = rr
    gset uu * gend = rr
    *
    * This is a standard (normal) log likelihood formula for any
    * multivariate GARCH model. The difference among these will be in the
    * definitions of HF and RESID. The function %XT pulls information out of
    * a matrix of SERIES.
    *
    declare frml[symm] hf
    *
    frml logl = $
        hx = hf(t) , $
        %do(i,1,n,u(i)=resid(i)) , $
        ux = %xt(u,t), $
        h(t)=hx, uu(t)=%outerxx(ux), $
        %logdensity(hx,ux)
    *****************************************************
    *
    * Panel GARCH - DVECH with restrictions. WISH TO ADD THE DUMMY VARIABLE ABOVE TO THE VARIANCE EQU TO GET ITS OVERALL EFFECT ON THE CONDITIONAL VARIANCE OF **THE PANEL. ALSO MAY WISH TO ADD FURTHER LAGGED VALUES OF UU   

    dec symm vcs(n,n)
    dec real delta lambda gamma rho duma
    dec symm vbs(n,n) vas(n,n) vdann(n,n)
    *
    compute vcs=rr*.1,delta=lambda=.8,gamma=rho=.1
    nonlin(parmset=garchparms) vcs delta lambda gamma rho
    frml hf = vcs+vbs.*h{1}+vas.*uu{1}
    *
    * Call once during START option to fill in the VAS and VBS arrays
    *
    function PGARCHInit
    local integer i j
    ewise vbs(i,j)=%if(i==j,delta,lambda)
    ewise vas(i,j)=%if(i==j,gamma,rho)
    end
    *
    maximize(start=PGARCHInit(),parmset=meanparms+garchparms,pmethod=simplex,piters=10,method=bfgs,iters=400) logl gstart gend
trish
 
Posts: 3
Joined: Wed Apr 04, 2012 4:49 am

Re: Panel Garch: coding general mean and conditional varian

Postby TomDoan » Fri Apr 06, 2012 9:54 am

Are you always using the same dummies for each i, just with different loadings? If so, you would just make the following adjustments:

dec symm vcs(n,n) vds(n,n)
dec real delta lambda gamma rho duma
dec symm vbs(n,n) vas(n,n) vdann(n,n)
*
compute vcs=rr*.1,delta=lambda=.8,gamma=rho=.1
compute vds=%zeros(n,n)
nonlin(parmset=garchparms) vcs vds delta lambda gamma rho
frml hf = vcs+vds*dumann1+vbs.*h{1}+vas.*uu{1}
TomDoan
 
Posts: 2718
Joined: Wed Nov 01, 2006 5:36 pm

Re: Panel Garch: coding general mean and conditional varian

Postby trish » Fri Apr 06, 2012 9:49 pm

Cheers and thank you for your prompt reply and for this solution. At the moment I am using the same dummies for each i but as I take the project forward this will change.
trish
 
Posts: 3
Joined: Wed Apr 04, 2012 4:49 am

Re: Panel Garch: coding general mean and conditional varian

Postby trish » Fri Apr 13, 2012 4:22 am

Hi Tom
Re above, I would be grateful if you could show me how to cope with different mean and variance slope dummies, say e.g. Dy1t*rt; Dy2t*rt; Dy3t*rt, where Dyit take different time series values of 1 and 0 depending on the variable being analyzed, (e.g. in the above example, y1=xjpn, y2=xfra, y3=xsui) and rt is an exogenous time series.
Thank you in advance.
trish
 
Posts: 3
Joined: Wed Apr 04, 2012 4:49 am

Re: Panel Garch: coding general mean and conditional varian

Postby debkaplan1970 » Mon May 06, 2013 11:11 am

Hello Tom:

Forgive me for asking a truly embarrassing question. After running the program below, how do save the residuals and conditional variance for further analysis? I have typed the following commands after the "maximize" statement without much success:

open copy mil_firms.xls
copy(format=xls,org=cols) gstart gend nresids cvar

Unfortunately, I have not used RATS for a while and feel totally rusty. Help me please.

Mbodja

Code: Select all
all 6237
    open data g10xrate.xls
    data(format=xls,org=columns) / usxjpn usxfra usxsui
*Bring in  dummy, say E.G. at obs 3000. Note that this is an identical dummy applied to each i in the panel

   dummy(ao=3000) dumann1 /
   dummy(ao=3000) dumann2 /
   dummy(ao=3000) dumann3 /
   *print / dumann1
    *
    set xjpn = 100.0*log(usxjpn/usxjpn{1})
    set xfra = 100.0*log(usxfra/usxfra{1})
    set xsui = 100.0*log(usxsui/usxsui{1})
    *
    * Estimation using MAXIMIZE
    * The initial few lines of this set the estimation range, which needs to
    * be done explicitly, and the number of variables. Then, vectors for the
    * dependent variables, residuals and residuals formulas are set up. The
    * SET instructions copy the dependent variables over into the slots in
    * the vector of series.
    *
    compute gstart=3,gend=6237
    compute n=3
    dec vect[series] y(n) u(n) yl1(n) dumann(n)
    dec vect[frml] resid(n)
    set y(1) = xjpn
    set y(2) = xfra
    set y(3) = xsui
    set yl1(1) = xjpn{1}
   set yl1(2) = xfra{1}
   set yl1(3) = xsui{1}
   set dumann(1) = dumann1
   set dumann(2) = dumann2
   set dumann(3) = dumann3
    *
    * This is specific to a mean-only model. It sets up the formulas (the &i
    * are needed in the formula definitions when the FRML is defined in a
    * loop), and estimates them using NLSYSTEM. This both initializes the
    * mean parameters, and computes the unconditional covariance matrix. If
    * you want more general mean equations, the simplest way to do that
    * would be to define each FRML separately.
    *
   dec vect b(n) ar(n) d(n)
   
   * Do it first with separate frms's
   *nonlin(parmset=meanparms) b1 b2 b3 ar1 ar2 ar3 d1 d2 d3
   *frml resid(1) = y(1)-b1-ar1*yl1(1)-d1*dumann(1)
   *frml resid(2) = y(2)-b2-ar2*yl1(2)-d2*dumann(2)
   *frml resid(3) = y(3)-b3-ar3*yl1(3)-d3*dumann(3)
   
   * Now do it in a loop to see if identical to above
   nonlin(parmset=meanparms) b ar d
    do i=1,n
       frml resid(i) = (y(&i)-b(&i)-ar(&i)*yl1(&i)-d(&i)*dumann(&i))
    end do i
    nlsystem(parmset=meanparms,resids=u) gstart gend resid
    compute rr=%sigma
   display rr

    *
    * The paths of the covariance matrices and uu' are saved in the
    * SERIES[SYMM] names H and UU. UX and HX are used to pull in residuals
    * and H matrices.
    *
    declare series[symm] h uu
    *
    * ux is used when extracting a u vector
    *
    declare symm hx(n,n)
    declare vect ux(n)
    *
    * These are used to initialize pre-sample variances.
    *
    gset h  * gend = rr
    gset uu * gend = rr
    *
    * This is a standard (normal) log likelihood formula for any
    * multivariate GARCH model. The difference among these will be in the
    * definitions of HF and RESID. The function %XT pulls information out of
    * a matrix of SERIES.
    *
    declare frml[symm] hf
    *
    frml logl = $
        hx = hf(t) , $
        %do(i,1,n,u(i)=resid(i)) , $
        ux = %xt(u,t), $
        h(t)=hx, uu(t)=%outerxx(ux), $
        %logdensity(hx,ux)
    *****************************************************
    *
    * Panel GARCH - DVECH with restrictions. WISH TO ADD THE DUMMY VARIABLE ABOVE TO THE VARIANCE EQU TO GET ITS OVERALL EFFECT ON THE CONDITIONAL VARIANCE OF **THE PANEL. ALSO MAY WISH TO ADD FURTHER LAGGED VALUES OF UU   

    dec symm vcs(n,n)
    dec real delta lambda gamma rho duma
    dec symm vbs(n,n) vas(n,n) vdann(n,n)
    *
    compute vcs=rr*.1,delta=lambda=.8,gamma=rho=.1
    nonlin(parmset=garchparms) vcs delta lambda gamma rho
    frml hf = vcs+vbs.*h{1}+vas.*uu{1}
    *
    * Call once during START option to fill in the VAS and VBS arrays
    *
    function PGARCHInit
    local integer i j
    ewise vbs(i,j)=%if(i==j,delta,lambda)
    ewise vas(i,j)=%if(i==j,gamma,rho)
    end
    *
    maximize(start=PGARCHInit(),parmset=meanparms+garchparms,pmethod=simplex,piters=10,method=bfgs,iters=400) logl gstart gend
debkaplan1970
 
Posts: 4
Joined: Tue Apr 24, 2012 8:16 pm

Re: Panel Garch: coding general mean and conditional varian

Postby TomDoan » Mon May 06, 2013 11:29 am

This is set up to give very similar results to a GARCH instruction. The residuals are in a VECT[SERIES] called U, so

open copy mil_firms.xls
copy(format=xls,org=cols) gstart gend u

will give you an XLS file with the residuals (in separate columns) for each variable.

The covariances are in a SERIES[SYMM] called HH. You have to split those off into separate series in order to export them. For instance

set h11 gstart gend = hh(t)(1,1)
set h12 gstart gend = hh(t)(1,2)

etc.
TomDoan
 
Posts: 2718
Joined: Wed Nov 01, 2006 5:36 pm

Re: Panel Garch: coding general mean and conditional varian

Postby debkaplan1970 » Mon May 06, 2013 1:00 pm

Dear Tom:

Thanks for your swift response. Regrettably, I am still not able to retrieve the residuals and the conditional variance following your guidance. Again I apologize for being such a nuisance but I don't know who else to turn to for help about this matter. Thank you so much.
debkaplan1970
 
Posts: 4
Joined: Tue Apr 24, 2012 8:16 pm

Re: Panel Garch: coding general mean and conditional varian

Postby TomDoan » Mon May 06, 2013 1:07 pm

debkaplan1970 wrote:Dear Tom:

Thanks for your swift response. Regrettably, I am still not able to retrieve the residuals and the conditional variance following your guidance. Again I apologize for being such a nuisance but I don't know who else to turn to for help about this matter. Thank you so much.


You'd have to post what you tried that didn't work.
TomDoan
 
Posts: 2718
Joined: Wed Nov 01, 2006 5:36 pm

Re: Panel Garch: coding general mean and conditional varian

Postby debkaplan1970 » Mon May 06, 2013 1:44 pm

The following is what I ran. I do get the estimates of the GARCH model. However, I am not able to retrieve the residual and conditional variance. Thanks again.


_______________________________________________________________________________________
Code: Select all
all 8000
OPEN DATA " C:\Documents and Settings\~oreo~\My Documents\WinRATS Standard 8.1\garch_data_2004.xls"
DATA(FORMAT=XLS,ORG=COLUMNS) 1 8000 elec_news_date PERMNO PERMCO HSICCD PRC VOL RET SHROUT vwretd stock_date year time
*
*set xjpn = 100.0*log(usxjpn/usxjpn{1})
    *set xfra = 100.0*log(usxfra/usxfra{1})
    *set xsui = 100.0*log(usxsui/usxsui{1})
    *
    * Estimation using MAXIMIZE
    * The initial few lines of this set the estimation range, which needs to be done explicitly, and the number of variables.
    * Then, vectors for the dependent variables, residuals and residuals formulas * are set up. The SET instructions copy
*
*slots in the vector of series.
    *
    compute gstart=2,gend=8000
    compute n=2
    dec vect[series] y(n) u(n)
    dec vect[frml] resid(n)
    set y(1) = ret
    set y(2) = vwretd
    *
    * This is specific to a mean-only model. It sets up the formulas (the &I are needed in the formula definitions when the FRML is defined in a loop), and estimates them using NLSYSTEM.
    * This both initializes the mean parameters, and c matrix. If you want more general mean equations, the simplest way to do that would be to define each FRML separately.
    *
    dec vect b(n)
    nonlin(parmset=meanparms) b
    do i=1,n
       frml resid(i) = (y(&i)-b(&i))
    end do i
    nlsystem(parmset=meanparms,resids=u) gstart gend resid
    compute rr=%sigma
    *
    * The paths of the covariance matrices and uu' are saved in the
    * SERIES[SYMM] names H and UU. UX and HX are used to pull in residuals and H matrices.
    *
    declare series[symm] h uu
    *
    * ux is used when extracting a u vector
    *
    declare symm hx(n,n)
    declare vect ux(n)
    *
    * These are used to initialize pre-sample variances.
    *
    gset h  * gend = rr
    gset uu * gend = rr
    *
    * This is a standard (normal) log likelihood formula for any multivariate GARCH model. The difference among these will be in the definitions of HF and RESID.
    * The function %XT pulls information out of a matrix of SERIES.
    *
    declare frml[symm] hf
    *
    frml logl = $
        hx = hf(t) , $
        %do(i,1,n,u(i)=resid(i)) , $
        ux = %xt(u,t), $
        h(t)=hx, uu(t)=%outerxx(ux), $
        %logdensity(hx,ux)
    *****************************************************
    *
    * Panel GARCH - DVECH with restrictions
    *
    dec symm vcs(n,n)
    dec real delta lambda gamma rho
    dec symm vbs(n,n) vas(n,n)
    *
    compute vcs=rr*.1,delta=lambda=.8,gamma=rho=.1
    nonlin(parmset=garchparms) vcs delta lambda gamma rho
    frml hf = vcs+vbs.*h{1}+vas.*uu{1}
    *
    * Call once during START option to fill in the VAS and VBS arrays
    *
    function PGARCHInit
    local integer i j
    ewise vbs(i,j)=%if(i==j,delta,lambda)
    ewise vas(i,j)=%if(i==j,gamma,rho)
    end
    *
maximize(start=PGARCHInit(),parmset=meanparms+garchparms,pmethod=simplex,piters=10,method=bfgs,iters=400) logl gstart gend
*
open copy mil_firms.xls
copy(format=xls,org=cols) gstart gend u
debkaplan1970
 
Posts: 4
Joined: Tue Apr 24, 2012 8:16 pm

Re: Panel Garch: coding general mean and conditional varian

Postby TomDoan » Mon May 06, 2013 2:25 pm

I'm not sure what you mean by not being able to retrieve the residuals. The residuals should be in the Excel file that you created.
TomDoan
 
Posts: 2718
Joined: Wed Nov 01, 2006 5:36 pm

Re: Panel Garch: coding general mean and conditional varian

Postby debkaplan1970 » Mon May 06, 2013 7:03 pm

The residuals should be in the Excel file I created but no such file is being created. This is so frustrating and embarrassing.
debkaplan1970
 
Posts: 4
Joined: Tue Apr 24, 2012 8:16 pm

Re: Panel Garch: coding general mean and conditional varian

Postby TomDoan » Mon May 06, 2013 8:45 pm

It has to be created. Put a full path name on it so you know exactly where it's going.
TomDoan
 
Posts: 2718
Joined: Wed Nov 01, 2006 5:36 pm


Return to ARCH and GARCH Models

Who is online

Users browsing this forum: No registered users and 1 guest

cron