Dynamic Conditional Beta

Discussions of ARCH, GARCH, and related models
Narci4269
Posts: 16
Joined: Sat Feb 06, 2021 5:29 am

Dynamic Conditional Beta

Unread post by Narci4269 »

Hi Tom. I´m trying to include Dynamic Conditional Betas (DCB) according to Engle (2016). Here is my code:

Code: Select all

cal(irregular)
all 1734
open data I:\EAFIT\Tesis\GPRK\Accion_GPRK_diaria_Final.xls
data(format=xls, org=obs)

**print(win = 'datos')

***** Data transformed *****

set us10y = us_10y; set ca10y = ca_10y; set caus = cad_usd; set eurus = eur_usd

dofor i = us10y ca10y embi_col smb hml rf erm
   set %s('r'+%l(i)) = i{0} / 252
end dofor

dofor i = gprk ecp gte pxt fec cne sp500 tsx brent vix us10y caus eurus copper
   set %s('l'+%l(i)) = log(i{0})
end dofor

dofor i = lgprk lecp lgte lpxt lfec lcne lsp500 ltsx rembi_col lus10y lbrent lvix lcaus leurus lcopper
   set %s('d'+%l(i)) = %if(%valid(i{0} - i{1}),(i{0} - i{1}),0)
end dofor

set dlptfw = wgprk*dlgprk+wecp*dlecp+wgte*dlgte+wpxt*(dlpxt - dlcaus)+wfec*(dlfec - dlcaus)+wcne*(dlcne - dlcaus)
set dlptfs 1 685 = (dlgprk + dlecp + dlgte + (dlpxt - dlcaus) + (dlcne - dlcaus))  / 5
set dlptfs 686 1734 = (dlgprk + dlecp + dlgte + (dlpxt - dlcaus) + (dlcne - dlcaus) + 1*(dlfec - dlcaus)) / 6

dofor i = dlpxt dlfec dlcne
   set %s(%l(i)) = i{0} - dlcaus
end dofor

dofor i = dlgprk dlecp dlgte dlpxt dlfec dlcne dlsp500 dlbrent dlcopper dlptfw dlptfs
   set %s('r'+%l(i)) = 100 * (i{0} - rf)
end dofor

dofor i = rsmb rhml rerm dlbrent drembi_col dleurus dlcopper dlus10y
   set %s(%l(i)) = 100 * i{0}
end dofor

***** GARCH Factors - BRENT *****

dec symm[series] hsfac(4,4) hsptw1(5,5) hsptw2(3,3) dcb(4,1)
clear(zeros) hsfac hsptw1 hsptw2 dcb
set d1 = t>=1521.and.t<=1524; set d2 = t==595; set d3 = t==1404

system(model = eqfac)
variables rdlsp500 rsmb rhml rdlBrent
lags 1 to 2
det constant
end(system)
estimate(noprint, resids = rfac, noftest)

garch(noprint, model=eqfac, mv=DCC, DCC=CDCC, p=1, q=1, hmatrices=hmfac, pmethod=simplex, piters=50, robusterros, $
      method=bhhh, iters=500, mvhseries=hsfac, distrib=t, asymm, stdresid=zfac, rvectors=r2fac, xreg) / $
      rdlsp500 rsmb rhml rdlBrent
      # d1 d2 d3

set mkptw1 = 0.0; set brptw1 = 0.0; set sbptw1 = 0.0; set hlptw1 = 0.0
set mkptw2 = 0.0; set brptw2 = 0.0

linreg(noprint, robust, define = eqptw1) rdlgprk / uptw1
# constant rdlsp500 mkptw1 rsmb sbptw1 rhml hlptw1 rdlBrent brptw1

group modpfw1 eqfac eqptw1

***** DCC *****

garch(model=modpfw1, mv=DCC, DCC=CDCC, p=1, q=1, hmatrices=hmptw1, pmethod=simplex, piters=50, robusterros, $
      method=bhhh, iters=500, mvhseries=hsptw1, distrib=ged, asymm, stdresid=zptw1, rvectors=rptw,  $
      hadjust=%(hsptw1(1,1)=hsfac(1,1),hsptw1(1,2)=hsfac(1,2),hsptw1(1,3)=hsfac(1,3),hsptw1(1,4)=hsfac(1,4), $
                hsptw1(2,2)=hsfac(2,2),hsptw1(2,3)=hsfac(2,3),hsptw1(2,4)=hsfac(2,4), $
                hsptw1(3,3)=hsfac(3,3),hsptw1(3,4)=hsfac(3,4),hsptw1(4,4)=hsfac(4,4))) / $
      rdlsp500 rsmb rhml rdlBrent rdlgprk
In hadjust I want to include a series called dcb(4,1). Each one has the calculation inv(%xsubmat(hmptw1(t),1,4,1,4))*tr(%xsubmat(hmptw1(t),5,5,1,4)).
The first series of dcb would have in every row an updated value (for each t) for the first parameter, Second series would a series for second parameter and so on. After that, I would create 4 series in hadjust: mkptw1 = rdlsp500*dcb(1,1), sbptw1= rsmb*dcb(2,1), hlptw1=rhml*dcb(3,1), and brptw1=rdlBrent*dcb(4,1)

I don't know how to nclude that in hadjust. Could you please help me?
Regards,
Narci4269
Posts: 16
Joined: Sat Feb 06, 2021 5:29 am

Re: Dynamic Conditional Beta

Unread post by Narci4269 »

Hi Tom. I am trying to do the calculations using maximize with the code below:

Code: Select all

cal(irregular)
all 1734
open data I:\EAFIT\Tesis\GPRK\Accion_GPRK_diaria_Final.xls
data(format=xls, org=obs)

**print(win = 'datos')

***** TRANSFORMACIÓN DE DATOS *****

set us10y = us_10y; set ca10y = ca_10y; set caus = cad_usd; set eurus = eur_usd

dofor i = us10y ca10y embi_col smb hml rf erm
   set %s('r'+%l(i)) = i{0} / 252
end dofor

dofor i = gprk ecp gte pxt fec cne sp500 tsx brent vix us10y caus eurus copper
   set %s('l'+%l(i)) = log(i{0})
end dofor

dofor i = lgprk lecp lgte lpxt lfec lcne lsp500 ltsx rembi_col lus10y lbrent lvix lcaus leurus lcopper
   set %s('d'+%l(i)) = %if(%valid(i{0} - i{1}),(i{0} - i{1}),0)
end dofor

set dlptfw = wgprk*dlgprk+wecp*dlecp+wgte*dlgte+wpxt*(dlpxt - dlcaus)+wfec*(dlfec - dlcaus)+wcne*(dlcne - dlcaus)
set dlptfs 1 685 = (dlgprk + dlecp + dlgte + (dlpxt - dlcaus) + (dlcne - dlcaus))  / 5
set dlptfs 686 1734 = (dlgprk + dlecp + dlgte + (dlpxt - dlcaus) + (dlcne - dlcaus) + 1*(dlfec - dlcaus)) / 6

dofor i = dlpxt dlfec dlcne
   set %s(%l(i)) = i{0} - dlcaus
end dofor

dofor i = dlgprk dlecp dlgte dlpxt dlfec dlcne dlsp500 dlbrent dlcopper dlptfw dlptfs
   set %s('r'+%l(i)) = 100 * (i{0} - rf)
end dofor

dofor i = rsmb rhml rerm dlbrent drembi_col dleurus dlcopper dlus10y
   set %s(%l(i)) = 100 * i{0}
end dofor

***** Mean Eq *****

vcv(matrix=jj, noprint, centered)
# rdlsp500 rsmb rhml rdlbrent rdlecp

com n = 5
dec vect[series] y(n) u(n)
dec vect[frml] resid(n)
dec series[symm] h uu
set y(1) = rdlsp500
set y(2) = rsmb
set y(3) = rhml
set y(4) = rdlBrent
set y(5) = rdlecp

clear u

linreg(noprint) rdlecp
# constant rdlsp500 rsmb rhml rdlbrent

compute ini=%imax(%regstart(),2),fin=%regend()

linreg(noprint) y(1) ini fin u(1)
# constant
com mk0 = %beta(1)

linreg(noprint) y(2) ini fin u(2)
# constant
com sb0 = %beta(1)

linreg(noprint) y(3) ini fin u(3)
# constant
com hl0 = %beta(1)

linreg(noprint) y(4) ini fin u(4)
# constant
com br0 = %beta(1)

set mkecp = 0.0; set sbecp = 0.0; set hlecp = 0.0; set brecp = 0.0

linreg(noprint) y(5) ini fin u(5)
# constant y(1) mkecp y(2) sbecp y(3) hlecp y(4) brecp

com b0 = %beta(1), b1 = %beta(2), b2 = %beta(3)
com b3 = %beta(4), b4 = %beta(5), b5 = %beta(6)
com b6 = %beta(7), b7 = %beta(8), b8 = %beta(9)

nonlin(parmset=meanparms) mk0 sb0 hl0 br0 b0 b1 b2 b3 b4 b5 b6 b7 b8

frml resid(1) = (y(1)-mk0)
frml resid(2) = (y(2)-sb0)
frml resid(3) = (y(3)-hl0)
frml resid(4) = (y(4)-br0)
frml resid(5) = (y(5)-b0-b1*y(1)-b2*mkecp-b3*y(2)-b4*sbecp-b5*y(3)-b6*hlecp-b7*y(4)-b8*brecp)

gset h  = %zeros(n,n)
vcv(matrix=rr,noprint, centered)
# u
*
* h will have the sequence of variance estimates
* uu will have the sequence of uu' matrices
*

*
* hx and uux are used when extracting elements from h and uu.
* ux is used when extracting a u vector
*
declare symm hx(n,n) uux(n,n)
declare vect ux(n)
*
* This is used to initialize pre-sample variances.
*
gset h = rr
gset uu = rr
*
* This is a standard log likelihood formula for any bivariate
* ARCH, GARCH, ARCH-M,... The difference among these will be in
* the definitions of HF and RESID.
*
declare frml[symm] hf
*

nonlin(parmset=distrib) nu
frml logl = $
%do(i,1,n,u(i)=resid(i)),$
hx = hf(t) , $
ux = %xt(u,t) , uux = %outerxx(ux),$
h(t) = hx , uu(t) = uux,$
%logtdensity(hx,ux,nu)
com nu = 6

***** DCC *****

dec vect vcv(n) vav(n) vbv(n)
com alpha=0.05, beta=0.90
*

function hfcccgarch time
type symm hfcccgarch
type integer time
do i=1,n
   compute hx(i,i)=vcv(i)+$
        vbv(i)*h(time-1)(i,i)+vav(i)*uu(time-1)(i,i)
   do j=1,i-1
     compute hx(i,j)=(1-alpha-beta)*jj(i,j)+alpha*uu(time-1)(i,j)+beta*h(time-1)(i,j)
   end do j
end do i
compute hfcccgarch=hx
end
*

dec rect dcb(fin,n-1)
do j = ini, fin
   com coeffs =  tr(inv(%xsubmat(h(j),1,4,1,4))*tr(%xsubmat(h(j),5,5,1,4)))
   do i = 1, n-1
      com dcb(j,i) = coeffs(1,i)
   end do i
end do j

set mkecp ini fin = dcb(t,1); set sbecp ini fin = dcb(t,2)
set hlecp ini fin = dcb(t,3); set brecp ini fin = dcb(t,4)

frml hf = hfcccgarch(t)
nonlin(parmset=garchparms) vcv vav vbv alpha beta
compute vcv=%xdiag(rr),vav=%const(0.05),vbv=%const(0.80)
maximize(parmset=meanparms+garchparms+distrib,$
         pmethod=simplex,piters=100,method=bfgs,iters=500) logl ini fin
I don´t know why there is no calculations for dcb arrengement. What could be wrong? Basically the idea is that dcb calculation be included in mean equation for stock returns (see frml resid(5)).
Regards,
Attachments
Accion_GPRK_diaria_Final.xls
(7.71 MiB) Downloaded 1022 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Dynamic Conditional Beta

Unread post by TomDoan »

What you're looking for is the %PT function, which splits a VECTOR up and puts the components elements of a VECT[SERIES]. You can also use the %SWEEPTOP function to do the projection. The following does the calculation you want for the 3 variable system from GARCHMV.RPF.

Code: Select all

open data g10xrate.xls
data(format=xls,org=columns) 1 6237 usxjpn usxfra usxsui
*
set xjpn = 100.0*log(usxjpn/usxjpn{1})
set xfra = 100.0*log(usxfra/usxfra{1})
set xsui = 100.0*log(usxsui/usxsui{1})
*
* Examples with the different choices for the MV option
*
dec vect[series] betas(2)
garch(p=1,q=1,pmethod=simplex,piters=10,hmatrices=hmat,$
   hadjust=%pt(betas,t,%xsubmat(%sweeptop(hmat(t),2),1,2,3,3))) / xjpn xfra xsui
Narci4269
Posts: 16
Joined: Sat Feb 06, 2021 5:29 am

Re: Dynamic Conditional Beta

Unread post by Narci4269 »

Tom perfect, very useful. It's working!
Thanks.
Post Reply