Code: Select all
setmaxerrs 1000
pageload dsdf.txt
system bg
bg.append df = c(1)
bg.append ds = c(2)
c = 0
bg.arch @ccc c arch(1) garch(1)
c = c/2
bg.arch @ccc c arch(1) garch(1)
freeze(mode=overwrite, ootb) bg.output
%tbc = ootb(9,1)
vector(3) vg
if @left(%tbc,20)="Convergence achieved" then
%date = @word(bg.@smpl,2)
bg.makegarch(date=%date, name=cv,mat)
bg.makeresids(bn=er)
' GARCH1 = C(3) + C(4)*RESID1(-1)^2 + C(5)*GARCH1(-1)
' GARCH2 = C(6) + C(7)*RESID2(-1)^2 + C(8)*GARCH2(-1)
' COV1_2 = C(9)*@SQRT(GARCH1*GARCH2)
!ccc = C(3) + C(4)*@elem(er01,%date)^2 + C(5)*cv(1,1)' GARCH1
!ccc = C(9)*@SQRT((C(6) + C(7)*@elem(er02,%date)^2 + C(8)*cv(2,2))/!ccc)' COV1_2/GARCH1
vg(1) = C(3) + C(4)*@elem(er01,%date)^2 + C(5)*cv(1,1)' GARCH1
vg(2) = C(6) + C(7)*@elem(er02,%date)^2 + C(8)*cv(2,2)' GARCH2
vg(3) = C(9)*@SQRT(vg(1)*vg(2))
else
!ccc = na
v = na
endif
'conditional beta (this is NOT hedge ratio, many guys have been trapped)
vector(3) vb
vb(1) = vg(3)/vg(1)
vb(2) = C(9)*@SQRT(vg(2)/vg(1))
vb(3) = !ccc
1 Is there any way to restrict the coefs in the individual variance equation to be positive? in this example, C(5) and C(8) are negative, such that the forecast variance GARCH2 is negative
2 When there is a numerical error, such as "square root of negative number", why not set the resulat to be NaN? In this example, three ways to compute the same formula, store in vector object vb, leads to different results.
