‘forum: http://forums.eviews.com/viewtopic.php?f=4&t=273
' BV_GARCH.PRG (3/30/2004)
' Revised for 6.0 (3/7/2007)
' example program for EViews LogL object
'
' restricted version of 
' bi-variate BEKK of Engle and Kroner (1995):
'
'  y = mu + res -> y = mu + res
'  res ~ N(0,H)
'
'  H = omega*omega' + alpha res(-1) res(-1)' alpha'+ beta H(-1) beta'
'
' where
'
'     y = 2 x 1
'     mu = 2 x 1
'      H = 3 x 3 (symmetric)
'         H(1,1) = variance of y1   (saved as var_y1)
'         H(1,2) = cov of y1 and y2 (saved as cov_y1y2)
'         H(1,3) = cov of y1 and y3 (saved as cov_y1y3)
'         H(2,2) = variance of y2   (saved as var_y2)
'         H(2,3) = cov of y2 and y3 (saved as cov_y2y3)
'         H(3,3) = variance of y3   (saved as var_y3)
'   omega = 3 x 3 (lower triangular) 
'   beta = 3 x 3 (diagonal)
'   alpha = 3 x 3 (diagonal)
'

' dependent variables of both series must be continues
smpl @all
series y1=dusa
series y2=demu
series y3 = dsa

' set sample 
' first observation of s1 need to be one or two periods after
' the first observation of s0 
sample s0 @first+1 @last
sample s1 @first+2 @last



' initialization of parameters and starting values
' change below only to change the specification of model 
smpl s0

'get starting values from univariate GARCH 
'equation eq1.arch(m=100,c=1e-5) y1 c
'equation eq2.arch(m=100,c=1e-5) y2 c

equation eq1.ARCH(BACKCAST=0.7,DERIV=AA) y1 c
equation eq2.ARCH(BACKCAST=0.7,DERIV=AA) y2 c
equation eq3.ARCH(BACKCAST=0.7,DERIV=AA) y3 c


'No need for specification of the conditional variances
‘eq1.makegarch garch1
‘eq2.makegarch garch2
‘eq3.makegarch garch3


' declare coef vectors to use in bi-variate GARCH model
' see above for details 
'coef(2) mu
' mu(1) = eq1.c(1)
' mu(2)= eq2.c(1)

'coef(3) omega
' omega(1)=(eq1.c(2))^.5
' omega(2)=0
' omega(3)=eq2.c(2)^.5

'coef(3) alpha
' alpha(1) = (eq1.c(3))^.5
‘ alpha(2) = 0.2
' alpha(2) = (eq2.c(3))^.5 

'coef(3) beta 
' beta(1)= (eq1.c(4))^.5 
‘ beta(2) = 0.2
' beta(2)= (eq2.c(4))^.5

'new values
    ' declare coef vectors to use in GARCH model

    coef(3) mu
    mu(1) = eq1.c(1)
    mu(2)= eq2.c(1)
    mu(3)= eq3.c(1)

    

    coef(6) omega
    omega(1)=(eq1.c(2))^.5
    omega(2)=0
    omega(3)=(eq2.c(2))^.5
    omega(4)=0
    omega(5)=0
    omega(6)=(eq3.c(2))^.5

    coef(6) alpha
    alpha(1) = (eq1.c(3))^.5
    alpha(2) =  0.15
    alpha(3) = (eq2.c(3))^.5
	alpha(4) = 0
	alpha(5) = 0
	alpha(6) = (eq3.c(3))^.5

    coef(6) beta
    beta(1)= (eq1.c(4))^.5
    beta(2)= 0.2
    beta(3)= (eq2.c(4))^.5
	beta(4)= 0
	beta(5)= 0
	beta(6)= (eq3.c(4))^.5



' constant adjustment for log likelihood
!mlog2pi = 3*log(2*@acos(-1))

'old values
' use var-cov of sample in "s1" as starting value of variance-covariance matrix
'series cov_y1y2 = @cov(y1-mu(1), y2-mu(2))
'series var_y1 = @var(y1)
'series var_y2 = @var(y2)

'series sqres1 = (y1-mu(1))^2
'series sqres2 = (y2-mu(2))^2
'series res1res2 = (y1-mu(1))*(y2-mu(2))

    series cov_y1y2 = @cov(y1-mu(1), y2-mu(2))
    series cov_y1y3 = @cov(y1-mu(1), y3-mu(3))
    series cov_y2y3 = @cov(y2-mu(2), y3-mu(3))

    series var_y1 = @var(y1)
    series var_y2 = @var(y2)
    series var_y3 = @var(y3)


    series sqres1 = (y1-mu(1))^2
    series sqres2 = (y2-mu(2))^2
    series sqres3 = (y3-mu(3))^2

    series res1res2 = (y1-mu(1))*(y2-mu(2))
    series res1res3 = (y1-mu(1))*(y3-mu(3))
    series res2res3 = (y2-mu(2))*(y3-mu(3))




' ...........................................................
' LOG LIKELIHOOD
' set up the likelihood 
' 1) open a new blank likelihood object (L.O.) name tvgarch
' 2) specify the log likelihood model by append
' ...........................................................

logl tvgarch
'old values
'tvgarch.append @logl logl
'tvgarch.append sqres1 = (y1-mu(1))^2
'tvgarch.append sqres2 = (y2-mu(2))^2
'tvgarch.append res1res2 = (y1-mu(1))*(y2-mu(2))

    ' squared errors and cross errors
    tvgarch.append @logl logl
    tvgarch.append sqres1 = (y1-mu(1))^2
    tvgarch.append sqres2 = (y2-mu(2))^2
    tvgarch.append sqres3 = (y3-mu(3))^2

    tvgarch.append res1res2 = (y1-mu(1))*(y2-mu(2))
    tvgarch.append res1res3 = (y1-mu(1))*(y3-mu(3))
    tvgarch.append res2res3 = (y2-mu(2))*(y3-mu(3))



' calculate the variance and covariance series
tvgarch.append var_y1  =  omega(1)^2+ alpha(1)^2*sqres1(-1)+2*alpha(1)*alpha(2)*res1res2(-1)+2*alpha(1)*alpha(4)*res1res3(-1)+ alpha(2)^2*sqres2(-1)+ 2*alpha(2)*alpha(4)*res2res3(-1) + alpha(4)^2*sqres3(-1)+beta(1)^2*var_y1(-1)+2*beta(1)*beta(2)*cov_y1y2(-1) +2*beta(1)*beta(4)*cov_y1y3(-1) +beta(2)^2*var_y2(-1)+ 2*beta(2)*beta(4)*cov_y2y3(-1) +beta(4)^2*var_y3(-1)

tvgarch.append var_y2  = omega(2)^2+ omega(4)^2+alpha(3)^2*sqres2(-1)+2*alpha(3)*alpha(5)*res2res3(-1)+alpha(5)^2*sqres3(-1)+ beta(3)^2*var_y2(-1)+ 2*beta(3)*beta(5)*cov_y2y3(-1) +beta(5)^2*var_y3(-1)


tvgarch.append var_y3 =  omega(3)^2+ omega(5)^2 + omega(6)^2+alpha(6)^2*sqres3(-1)+ beta(6)^2*var_y3(-1)

tvgarch.append cov_y1y2 = omega(1)*omega(2)+alpha(1)*alpha(3)*res1res2(-1)+ alpha(1)*alpha(5)*res1res3(-1)+ alpha(2)*alpha(3)*sqres2(-1) + alpha(2)*alpha(5)*res2res3(-1)+ alpha(3)*alpha(4)*res2res3(-1) + alpha(4)*alpha(5)*sqres3(-1)+ beta(1)*beta(3)*cov_y1y2(-1)+ beta(1)*beta(5)*cov_y1y3(-1)+ beta(2)*beta(3)*var_y2(-1)+ beta(2)*beta(5)*cov_y2y3(-1) + beta(3)*beta(4)*cov_y2y3(-1)+ beta(4)*beta(5)*var_y3(-1)

tvgarch.append cov_y1y3 = omega(1)*omega(3)+alpha(1)*alpha(6)*res1res3(-1)+alpha(2)*alpha(6)*res2res3(-1)+alpha(4)*alpha(6)*sqres3(-1)+ beta(1)*beta(6)*cov_y1y3(-1)+ beta(2)*beta(6)*cov_y2y3(-1)+ beta(4)*beta(6)*var_y3(-1)

tvgarch.append cov_y2y3 = omega(2)*omega(3)+ omega(4)*omega(5)+alpha(3)*alpha(6)*res2res3(-1)+alpha(5)*alpha(6)*sqres3(-1)+beta(3)*beta(6)*cov_y2y3(-1)+beta(5)*beta(6)*var_y3(-1)
' determinant of the variance-covariance matrix
tvgarch.append deth = var_y1*var_y2*var_y3 

' inverse elements of the variance-covariance matrix
tvgarch.append invh1 = (var_y2*var_y3)/deth
tvgarch.append invh2 = 0/deth
tvgarch.append invh3 = 0/deth
tvgarch.append invh4 = (var_y1*var_y3)/deth
tvgarch.append invh5 = 0/deth
tvgarch.append invh6 = (var_y1*var_y2)/deth

' log-likelihood series
tvgarch.append logl = -0.5*(!mlog2pi + (invh1*sqres1+invh4*sqres2+invh6*sqres3) + log(deth))

' remove some of the intermediary series
' tvgarch.append @temp invh1 invh2 invh3 sqres1 sqres2 res1res2 deth


' estimate the model
smpl s1
tvgarch.ml(showopts, m=150, c=1e-5)
' change below to display different output
show tvgarch.output
graph var.line var_y1 var_y2 var_y3
graph cov.line cov_y1y2 cov_y1y3 cov_y2y3
show var
show cov

' LR statistic for univariate vs trivariate
'scalar lr = -2*(eq1.@logl + eq2.@logl + eq3.@logl - tvgarch.@logl)
'scalar lr_pval = 1 - @cchisq(lr,3)

‘bv dcc for each pair:

graph rho12.line cov_y1y2/(@sqrt(var_y1)*@sqrt(var_y2))
graph rho13.line cov_y1y3/(@sqrt(var_y1)*@sqrt(var_y3))
graph rho23.line cov_y1y2/(@sqrt(var_y2)*@sqrt(var_y3))

show rho12
show rho13
show rho23
