Page 1 of 1

negative variance, square root of negative number

Posted: Sat Jun 27, 2015 3:01 am
by maxchen
EViews8Patch_042715

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
dsdf.txt
price change of spot and future
(665 Bytes) Downloaded 632 times
My questions
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.

Re: negative variance, square root of negative number

Posted: Sat Jun 27, 2015 3:16 am
by maxchen
When I am running CCC-GARCH for hundreds of time in a prg
1 check if convergence achieved or not
2 compute forecast conditional beta (cov/var)
My suggestion
1 provide data member to read convergence state, num of iterations
2 if log/sqrt of negative number, return NA, or some other options