Page 1 of 2
Bivariate Garch Model with dummy and interactions
Posted: Thu May 05, 2016 7:38 am
by Jason Gong
Dear Tom,
I wish to run a bivariate Garch model similar to the one in section 5.3.1 Sun et. al. 2009 (Sun, Q., Tong, W. H., & Yan, Y. (2009). Market liberalization within a country. Journal of Empirical Finance, 16(1), 18-41.). The model I intend to run is in the attached pic. Ra and Rb are stock returns in two markets and D1 is a dummy variable indicating a time period. I wonder how can I run this model in RATS?
Thanks a lot!
Best,
Jason
Re: Bivariate Garch Model with dummy and interactions
Posted: Tue May 10, 2016 11:08 am
by TomDoan
That's an extension of a "spillover" CC model. The attached program applies that to a pair of series from one of our stock data sets.
Re: Bivariate Garch Model with dummy and interactions
Posted: Fri May 13, 2016 10:20 am
by Jason Gong
Hi Tom,
I know it is a lot to ask, I wonder if can I put the one lagged return in each mean equation? What adjustments shall I do to the codes you wrote before?
Thank you so much!
Best,
Jason
Re: Bivariate Garch Model with dummy and interactions
Posted: Fri May 13, 2016 10:26 am
by TomDoan
Sure. Just change the mean equations:
equation eqn(1) xfra
# constant dummy
equation eqn(2) xsui
# constant dummy
to add the lagged dependent variable to each (xfra{1} in the first equation, xsui{1} in the second).
Re: Bivariate Garch Model with dummy and interactions
Posted: Tue Jul 26, 2016 4:02 am
by Lena
Hi Tom,
thank you for providing the code! I am wondering how to include a second or even third dummy variable in the model very much like in the Sun et. al. 2009 paper.
I do understand that QC and QCD change their dimensions but I really get confused when it comes to the part where the vector of variances allowing for the dummies in the spillover is calculated.
I would greatly appreciate any advice!
Best,
Lena
Re: Bivariate Garch Model with dummy and interactions
Posted: Tue Jul 26, 2016 4:21 pm
by TomDoan
The paper has three time segments, so there are just two dummies in addition to the "constants". You don't change the dimensions of QCD (and VARD), you introduce another similarly dimensioned matrix for each. Assuming dummy2 is your second dummy variables, you would need something like:
dec rect var(n,n) vard(n,n) vard2(n,n)
*
* QC is the subdiagonal of the standard CC
* QCD is the subdiagonal of the dummied CC
*
dec symm qc(n-1,n-1) qcd(n-1,n-1) qcd2(n-1,n-1)
Then the spillover function would need the third line added to the J loop
do j=1,n
compute hv(i)+=var(i,j)*uu(time-1)(j,j)
compute hv(i)+=vard(i,j)*uu(time-1)(j,j)*dummy(time)
compute hv(i)+=vard2(i,j)*uu(time-1)(j,j)*dummy2(time)
end do j
and you would need to add the second dummy shift to the calculation of HF
frml hf = %corrtocv(%%corrfromsubd(qc+qcd*dummy+qcd2*dummy2),varspilloverdummy(t))
Re: Bivariate Garch Model with dummy and interactions
Posted: Tue Dec 06, 2016 8:28 am
by Lena
Dear Tom,
I was wondering whether it might be possible to combine the bivariate GARCH with dummies with your program to estimate the Hafner-Herwartz volatility impulse response functions.
And if so, could you give me some guidance here?
Thanks in advance for your reply,
Lena
Re: Bivariate Garch Model with dummy and interactions
Posted: Tue Dec 06, 2016 1:20 pm
by TomDoan
The Hafner-Herwartz calculation is specifically for a "VECH" form GARCH model (which includes the BEKK model that they use). However, the same idea can apply to this type of model since the variances have the same type of extrapolation, as their recursion depends only upon lagged variances and lagged squared residuals (which have an expectation equal to the variance). I assume you mean to have a different calculation for each value of the dummies (i.e. three different VIRF's depending upon the branch).
Re: Bivariate Garch Model with dummy and interactions
Posted: Tue Dec 06, 2016 1:47 pm
by Lena
Thanks Tom for your rapid response!! Excactly, there must be several calculations for the VIRFs depending on the number of dummies included.
I am not sure how to combine these two programs to solve this problem ( especially because I do have difficulties in understanding your code for the VIRFs).
I'm really seeking for your help! If it would not be too much trouble, I would appreciate if you could help me with this.
Lena
Re: Bivariate Garch Model with dummy and interactions
Posted: Tue Dec 06, 2016 4:09 pm
by TomDoan
Hafner-Herwartz is covered in detail as part of the
GARCH e-course. Unlike HH, which does a recursion on the VECH representation, this would only do a recursion on the variances alone (the variances don't interact with the covariances in this model). The recursion takes exactly the same form, it's just that the matrices remove all rows and columns which correspond to the covariances.
Re: Bivariate Garch Model with dummy and interactions
Posted: Thu Dec 08, 2016 6:56 am
by Lena
Thanks Tom!
I still have another question. What do I use for the residuals rv and the variance hh in
compute eps0=rv(blackwed)
compute sigma0=hh(blackwed) ?
I might get the residuals with %resids but what about the variance?
Thanks!
Lena
Re: Bivariate Garch Model with dummy and interactions
Posted: Thu Dec 08, 2016 11:35 am
by TomDoan
If t0 is the position which is being used to determine the shock, then something like
compute eps0=rv(t0).^2
compute sigma0=%xdiag(hh(t0))
will create the two N-vectors that would be used in starting the recursion.
Re: Bivariate Garch Model with dummy and interactions
Posted: Mon Dec 12, 2016 8:57 am
by Lena
Dear Tom,
many thanks for your reply!
So I combined garchdummyspillover.rpf and garchmodels.rpf .
However, I still don't now how to specify the shock for the VIRFs.
In
Code: Select all
compute eps0=rv(ecpolicy).^2
compute sigma0=%xdiag(hf(blackwed))
I use the residuals rv from the base model ( which obviously is wrong!) and
for the calculation of sigma0 I use hf. Is this correct? What do I have to use instead?
It would be great if you could find the time to look over the code for me. I used your data g10xrate.xls and the dummy and shock dates are
chosen randomly.
Tanks in advance!
Lena
Code: Select all
*
* Example of a CC-spillover model with a single dummy break applied to the mean,
* spillover variances and CC matrix as in Sun, Tong and Yan(2009), "Market
* liberalization within a country," Journal of Empirical Finance, vol. 16, no 1,
* 18-41.
*
* This is applied to the data set used in the GARCHMV.RPF example.
*
all 3720
open data xrates.xls
data(format=xls,org=columns) / DATE USXFRA USXSUI
*
set xfra = 100.0*log(USXFRA/USXFRA{1})
set xsui = 100.0*log(USXSUI/USXSUI{1})
*
* The base model is a CC with VARIANCES=SPILLOVER.
*
garch(mv=cc,variances=spillover,rvectors=rv,derives=dd) / xfra xsui
*
* Somewhat interestingly (given that it's just one of our standard datasets), the
* fluctuation statistics show that a distinct break in the CC coefficient (at
* around entry 2725) *is* a distinct possibility.
*
@flux
# dd
acc dd(11) / ddcc
graph(footer="Accumulated gradients of CC parameter")
# ddcc
*
set dummy = t>=2725
*
* Estimation using MAXIMIZE
* The initial few lines of this set the estimation range, which needs to
* be done explicitly, and the number of variables.
*
compute gstart=2,gend=3720
compute n=2
*
dec vect[series] u(n)
dec series[symm] h uu
*
dec vect[equation] eqn(n)
dec vect[vect] bmean(n)
nonlin(parmset=meanparms) bmean
*
* Mean equations
*
equation eqn(1) xfra
# constant dummy
equation eqn(2) xsui
# constant dummy
*
* Estimate by OLS to get guess values
*
do i=1,n
linreg(equation=eqn(i))
compute bmean(i)=%beta
set u(i) = %resids
end do i
*
* Get the covariance matrix of the OLS residuals to get presample values for the H
* matrices and to use for guess values for the GARCH parameters.
*
vcv
# u
compute rr=%sigma
*
* 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)=%eqnrvalue(eqn(i),t,bmean(i))), $
ux = %xt(u,t),$
h(t)=hx, uu(t)=%outerxx(ux),$
%logdensity(hx,ux)
*****************************************************
*
* VCV is the VECTOR of variance constants
* VBV is the VECTOR of "GARCH" parameters
* VAR is the RECTANGULAR of standard spillover parameters
* VARD is the RECTANGULAR of dummied spillover parameters
*
dec vect vcv(n) vbv(n)
dec rect var(n,n) vard(n,n)
*
* QC is the subdiagonal of the standard CC
* QCD is the subdiagonal of the dummied CC
*
dec symm qc(n-1,n-1) qcd(n-1,n-1)
*
* This computes the VECTOR of variances allowing for the dummies in the spillover
* terms.
*
function varspilloverdummy time
type vector varspilloverdummy
type integer time
*
local integer i j
local vect hv(n)
*
do i=1,n
compute hv(i)=vcv(i)+vbv(i)*h(time-1)(i,i)
do j=1,n
compute hv(i)+=var(i,j)*uu(time-1)(j,j)
compute hv(i)+=vard(i,j)*uu(time-1)(j,j)*dummy(time)
end do j
end do i
*
compute varspilloverdummy=hv
end
* This converts the subdiagonal correlation to a full correlation matrix.
*
function %%corrfromsubd corrsubd
type symmetric %%corrfromsubd corrsubd
*
dim %%corrfromsubd(%rows(corrsubd)+1,%rows(corrsubd)+1)
ewise %%corrfromsubd(i,j)=%if(i==j,1.0,corrsubd(i-1,j))
end
*
* Compute the covariance matrix from the time-varying correlation matrix
* subdiagonal, and the spillover variance.
*
frml hf = %corrtocv(%%corrfromsubd(qc+qcd*dummy),varspilloverdummy(t))
* Guess values for GARCH parameters
*
ewise vbv(i)=.45
ewise var(i,j)=.05*(i==j)
ewise vcv(i)=rr(i,i)*(1-vbv(i)-var(i,i))
*
compute vard=%zeros(n,n)
ewise qc(i,j)=.5
compute qcd=%zeros(n-1,n-1)
*
nonlin(parmset=garchparms) vcv vbv var vard qc qcd
maximize(parmset=meanparms+garchparms,$
pmethod=simplex,piters=10,method=bfgs,iters=400) logl gstart gend
* VIRF with historical incidents
*
sstats(max) / %if(date==800201,t,0)>>xblackwed %if(date==930802,t,0)>>xecpolicy
compute blackwed=fix(xblackwed),ecpolicy=fix(xecpolicy)
compute nstep=400
spgraph(vfields=2,hfields=2,footer="Figure 1",$
xlabels=||"1992 Sept 16","1993 Aug 2"||,$
ylabels=||"FRA/USD Variance","SUI/USD Variance"||)
*
* Black Wednesday shocks. These are computed using a baseline of the
* estimated volatility state, so they are excess over the predicted
* covariance.
*
compute eps0=rv(blackwed).^2
compute sigma0=%xdiag(hf(blackwed))
compute shock=eps0-sigma0
*
* This generates responses for the 2 elements of the covariance matrix,
* which will be (in order) the (1,1) and (2,2).
*
dec vect[series] sept92virf(2)
do i=1,2
set sept92virf(i) 1 nstep = 0.0
end do i
*
*
do step=1,nstep
if step==1
compute hvec=%diag(vbv)*shock
else
compute hvec=(%diag(vbv)+%diag(%xdiag(var)))*hvec
compute %pt(sept92virf,step,hvec)
end do step
do i=1,2
graph(min=0.0,column=1,row=i,picture="*.###",vticks=5)
# sept92virf(i) 1 nstep
end do i
* EC Policy Change shock. These use a baseline of zero.
*
compute eps0=rv(ecpolicy).^2
compute sigma0=%xdiag(hf(ecpolicy))
compute shock=eps0-sigma0
*
dec vect[series] aug93virf(2)
do i=1,2
set aug93virf(i) 1 nstep = 0.0
end do i
*
do step=1,nstep
if step==1
compute hvec=%diag(vbv)*shock
else
compute hvec=(%diag(vbv)+%diag(%xdiag(vard)))*hvec
compute %pt(aug93virf,step,hvec)
end do step
*
do i=1,2
graph(min=0.0,column=2,row=i,picture="*.###",vticks=5)
# aug93virf(i) 1 nstep
end do i
spgraph(done)
Re: Bivariate Garch Model with dummy and interactions
Posted: Tue Dec 13, 2016 1:35 pm
by TomDoan
You're being a bit too literal in adapting the HH example---the search across the dates for the conditioning period is specific to the way their data set is constructed, and there's no reason to try to mimic it. I've written an example which does the VIRF's for this type of model. Now, this relies upon using a standard GARCH model, but all you would have to do is replace the procedure call which pulls out the matrices from GARCH output with something that pulls them out of your parameter set.
GARCHVIRFDIAG.RPF
Re: Bivariate Garch Model with dummy and interactions
Posted: Wed Dec 14, 2016 3:03 am
by Lena
Thank you so much Tom!
Just to make it clear (sorry!), I do have to adapt mvgarchvarmats.rpf since my condtional variance includes the dummy, right?
Best
Lena