R中的garchFit()在所有拟合值中返回相同的数字

R中的garchFit()在所有拟合值中返回相同的数字,r,statistics,R,Statistics,我试着在R中使用garchFit,发现了一些非常奇怪的东西,似乎所有的配件都是一样的。我尝试在R页面中使用该示例,并发现了相同的结果 如果打开R并键入以下内容: library(fGarch); ## UNIVARIATE TIME SERIES INPUT: # In the univariate case the lhs formula has not to be specified ... # A numeric Vector from default GARCH(1,1) - fix t

我试着在R中使用garchFit,发现了一些非常奇怪的东西,似乎所有的配件都是一样的。我尝试在R页面中使用该示例,并发现了相同的结果

如果打开R并键入以下内容:

library(fGarch);
## UNIVARIATE TIME SERIES INPUT:
# In the univariate case the lhs formula has not to be specified ...
# A numeric Vector from default GARCH(1,1) - fix the seed:
N = 200
x.vec = as.vector(garchSim(garchSpec(rseed = 1985), n = N)[,1])
garchFit(~ garch(1,1), data = x.vec, trace = FALSE)
# An univariate timeSeries object with dummy dates:
x.timeSeries = dummyDailySeries(matrix(x.vec), units = "GARCH11")
gfit = garchFit(~ garch(1,1), data = x.timeSeries, trace = FALSE)
然后,执行以下健全性检查似乎表明残差计算正确:

gfit@residuals == (x.vec - gfit@fitted)
但是,如果您检查gfit@fitted,可以看到所有的值都是相同的!那么基本上garchFit函数找到了一条水平线


这是本例中所期望的吗?

GARCH对序列的方差进行建模,因此我们不会期望拟合值(序列平均值的估计)发生变化,因为您所做的只是为方差指定了一个模型

这意味着您拟合的模型中的平均值存在ARMA(0,0):

R> gfit = garchFit(~ garch(1,1), data = x.timeSeries, trace = TRUE)

Series Initialization:
 ARMA Model:                arma
 Formula Mean:              ~ arma(0, 0)
 GARCH Model:               garch
 Formula Variance:          ~ garch(1, 1)
如果使用均值和方差模型拟合序列,则拟合值会发生变化:

R> gfit2 = garchFit(~ arma(1,1) + garch(1,1), data = x.timeSeries, trace = FALSE)
R> head(gfit2@fitted)
   1970-01-01    1970-01-02    1970-01-03    1970-01-04    1970-01-05 
-0.0010093158 -0.0004840687 -0.0002678956 -0.0006093776 -0.0003781936 
   1970-01-06 
 0.0004521798

GARCH对序列的方差进行建模,因此我们不希望拟合值(序列平均值的估计)发生变化,因为您所做的只是为方差指定一个模型

这意味着您拟合的模型中的平均值存在ARMA(0,0):

R> gfit = garchFit(~ garch(1,1), data = x.timeSeries, trace = TRUE)

Series Initialization:
 ARMA Model:                arma
 Formula Mean:              ~ arma(0, 0)
 GARCH Model:               garch
 Formula Variance:          ~ garch(1, 1)
如果使用均值和方差模型拟合序列,则拟合值会发生变化:

R> gfit2 = garchFit(~ arma(1,1) + garch(1,1), data = x.timeSeries, trace = FALSE)
R> head(gfit2@fitted)
   1970-01-01    1970-01-02    1970-01-03    1970-01-04    1970-01-05 
-0.0010093158 -0.0004840687 -0.0002678956 -0.0006093776 -0.0003781936 
   1970-01-06 
 0.0004521798

这一切都是有道理的,但我想要的是对波动性本身进行建模。有什么简单的方法可以得到二次变化(波动率)的拟合序列吗?
gfit2@h.t
给你想要的。请参见
?garchFit
中的描述,我想您已经读过了?我读过它,但之前是为了理解S4类是什么,所以当时我不理解它。谢谢你,加文!这一切都是有道理的,但我想要的是对波动性本身进行建模。有什么简单的方法可以得到二次变化(波动率)的拟合序列吗?
gfit2@h.t
给你想要的。请参见
?garchFit
中的描述,我想您已经读过了?我读过它,但之前是为了理解S4类是什么,所以当时我不理解它。谢谢你,加文!