楼主: helen_7
8646 18

[问答] garch程序出错:'singular covariance-coefficients are not unique' [推广有奖]

11
helen_7 发表于 2011-5-4 00:45:58 |只看作者 |坛友微信交流群
解决了,改变初值的设定就没再出错了

使用道具

12
helen_7 发表于 2011-5-9 01:44:30 |只看作者 |坛友微信交流群
11# ylhsu
ylhsu 你好!非常感谢你,虽然我在之前也基本上做好了,但是研究了你的程序后给了我一些启发。

使用道具

13
ylhsu 发表于 2011-5-9 16:10:48 |只看作者 |坛友微信交流群
12# helen_7


1.最正確的 GARCHM 模型設定應該是 Garchm_SD

2.只能做一次反覆估計的結果都不是 Global Maximum

3.因為估計準則是要 Maximize Likelihood, 所以必需改變初值設定後再比較 Log Likelihood 是否有增加

4.若有增加, 表示原來的結果只是 Local Maximum

5.GARCHM 模型收起始值影響很大, 也很敏感, 必需要有耐心不斷嘗試才可估計出合理又意義的係數結果
已有 1 人评分经验 论坛币 收起 理由
胖胖小龟宝 + 10 + 10 热心帮助其他会员

总评分: 经验 + 10  论坛币 + 10   查看全部评分

使用道具

14
helen_7 发表于 2011-5-14 21:21:28 |只看作者 |坛友微信交流群
13# ylhsu
谢谢你,ylhsu。对于第一个问题,我是要做CAPM模型,所以应该是均值方程里应该是方差,而不是标准差。
对与您后面提到的问题,的确需要耐心慢慢调试,目前还没有得到最优结果。
对于您的耐心指导再次表示感谢!{:2_31:}

使用道具

15
ylhsu 发表于 2011-5-14 23:31:08 |只看作者 |坛友微信交流群
14# helen_7

了解, 有空再幫你試試

使用道具

16
ylhsu 发表于 2011-5-15 19:23:58 |只看作者 |坛友微信交流群
15# ylhsu

這是依你原程式所改寫之程式, 結果還不錯

CAPM.txt

4.93 KB

使用道具

17
lengyue0937 发表于 2011-6-19 20:26:33 |只看作者 |坛友微信交流群
11# helen_7 你好!我也遇到了同样的问题。麻烦教我一下是怎样改变初值的设置的,改成什么?谢谢啦!

使用道具

18
luckyart 发表于 2012-5-28 23:21:55 |只看作者 |坛友微信交流群
看了你的程序。 你做的是三元多角化的GARCH。 Eview里面就有一个参考的例子。
不知道你有没有做非对角化的GARCH呢?

有的话,可以相互交流一下。

使用道具

19
shitouji2012 发表于 2013-12-30 18:09:26 |只看作者 |坛友微信交流群
ylhsu 发表于 2011-5-2 22:44
10# helen_7
您好,冒昧打扰,请不吝赐教!
我做三元bekk模型时出现如下错误
attempt to raise a negative number to a non integer power in "BETA(2)=```````"
请问是哪里出了错误。
' TV_GARCH.PRG (10/10/2000)
' example program for EViews LogL object
' revised for version 5.0 (11/19/2009)
'
' restricted version of
' tri-variate BEKK of Engle and Kroner (1995):
'
'  y = mu + res
'  res ~ N(0,H)
'
'  H = omega*omega' + beta H(-1) beta' + alpha res(-1) res(-1)' alpha'
'
'  where,
'     y = 3 x 1
'    mu = 3 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 y2 (saved as cov_y1y3)
'         H(2,2) = variance of y2   (saved as var_y2)
'         H(2,3) = cov of y1 and y3 (saved as cov_y2y3)
'         H(3,3) = variance of y3   (saved as var_y3)
' omega = 3 x 3 low triangular
'  beta = 3 x 3 diagonal
' alpha = 3 x 3 diagonal
'

'change path to program path
%path = @runpath
cd %path

' load workfile
load sj.wf1

' dependent variables of all series must be continues
series y1 = gdp
series y2 = m2
series y3 = sz

' set sample
' first observation of s1 need to be one or two periods after
' the first observation of s0
sample s0 1997Q1 2013Q3
sample s1 1997Q2 2013Q3

' 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 eq3.arch(m=100,c=1e-5) y3 c

' declare coef vectors to use in GARCH model
coef(3) mu
mu(1) = eq1.c(1)
mu(2) = eq2.c(1)
mu(3) = eq2.c(1)

coef(6) omega
omega(1) = (eq1.c(2))^.5
omega(2) = 0
omega(3) = 0
omega(4) = eq2.c(2)^.5
omega(5) = 0
omega(6) = eq3.c(2)^.5

coef(3) alpha
alpha(1) = (eq1.c(3))^.5
alpha(2) = (eq2.c(3))^.5
alpha(3) = (eq2.c(3))^.5

coef(3) beta
beta(1) = (eq1.c(4))^.5
beta(2) = (eq2.c(4))^.5
beta(3) = (eq3.c(4))^.5


' use sample var-cov as starting value of variance-covariance matrix

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 = (y3-mu(3))*(y2-mu(2))

' constant adjustment for log likelihood
!mlog2pi = 3*log(2*@acos(-1))


' ...........................................................
' LOG LIKELIHOOD
' set up the likelihood
' 1) open a new blank likelihood object name tvgarch
' 2) specify the log likelihood model by append
' ...........................................................

logl tvgarch

' 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 = (y3-mu(3))*(y2-mu(2))

' variance and covariance series
tvgarch.append var_y1  =  omega(1)^2 + beta(1)^2*var_y1(-1) + alpha(1)^2*sqres1(-1)
tvgarch.append var_y2  = omega(2)^2+omega(4)^2 + beta(2)^2*var_y2(-1) + alpha(2)^2*sqres2(-1)
tvgarch.append var_y3  = omega(3)^2+omega(5)^2+omega(6)^2 + beta(3)^2*var_y3(-1) + alpha(3)^2*sqres3(-1)

tvgarch.append cov_y1y2 = omega(1)*omega(2) + beta(2)*beta(1)*cov_y1y2(-1) + alpha(2)*alpha(1)*res1res2(-1)
tvgarch.append cov_y1y3 = omega(1)*omega(3) + beta(3)*beta(1)*cov_y1y3(-1) + alpha(3)*alpha(1)*res1res3(-1)
tvgarch.append cov_y2y3 = omega(2)*omega(3) + omega(4)*omega(5) + beta(3)*beta(2)*cov_y2y3(-1) + alpha(3)*alpha(2)*res2res3(-1)

' determinant of the variance-covariance matrix
tvgarch.append deth = var_y1*var_y2*var_y3 - var_y1*cov_y2y3^2-cov_y1y2^2*var_y3+2*cov_y1y2*cov_y2y3*cov_y1y3-cov_y1y3^2*var_y2

' calculate the elements of the inverse of var_cov (H) matrix
' numbered as vech(inv(H))
tvgarch.append invh1 = (var_y2*var_y3-cov_y2y3^2)/deth
tvgarch.append invh2 = -(cov_y1y2*var_y3-cov_y1y3*cov_y2y3)/deth
tvgarch.append invh3 = (cov_y1y2*cov_y2y3-cov_y1y3*var_y2)/deth
tvgarch.append invh4 = (var_y1*var_y3-cov_y1y3^2)/deth
tvgarch.append invh5 = -(var_y1*cov_y2y3-cov_y1y2*cov_y1y3)/deth
tvgarch.append invh6 = (var_y1*var_y2-cov_y1y2^2)/deth

' log-likelihood series
tvgarch.append logl = -0.5*(!mlog2pi + (invh1*sqres1+invh4*sqres2+invh6*sqres3 +2*invh2*res1res2 +2*invh3*res1res3+2*invh5*res2res3 ) + log(deth))

' remove some of the intermediary series
'tvgarch.append @temp invh1 invh2 invh3 invh4 invh5 invh6 sqres1 sqres2 sqres3 res1res2 res1res3 res2res3 deth

' estimate the model
smpl s1
tvgarch.ml(showopts, m=100, 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)


使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-6-3 14:27