简体   繁体   English

使用 rugarch 包在 R 中进行 GARCH 参数估计和预测

[英]GARCH parameter estimation and forecast in R with rugarch package

I have a problem with parameter estimation and forecast for a GARCH model.我对 GARCH 模型的参数估计和预测有问题。 I have a time series of volatilities, starting in 1996 and ending in 2009. I tried to estimate the parameters with the ugarchspec and ugarchfit function:我有一个时间序列的波动率,从 1996 年开始到 2009 年结束。我尝试使用ugarchspecugarchfit函数估计参数:

garch1.1 <- ugarchspec(variance.model=list(model="sGARCH", garchOrder=c(1,1)),mean.model=list(armaOrder=c(0,0)),distribution="std")
garch1.1fit <- ugarchfit(spec=garch1.1,data=RV)

The results seemed to be okay, so I went on with the forecast.结果似乎没问题,所以我继续预测。 I wanted to use the ugarchforecast or ugarchroll function.我想使用ugarchforecastugarchroll函数。 But when I tried to do it, I recognized that they work with the wrong date.但是当我尝试这样做时,我意识到他们使用了错误的日期。 For example, If I try to do a simple forecast like例如,如果我尝试做一个简单的预测,比如

forecast <- ugarchforecast(garch1.1fit,n.ahead=2)

I get the following results:我得到以下结果:

0-roll forecast [T0=1979-04-05 01:00:00]:
    Series     Sigma
T+1  5.373e-05 3.733e-05
T+2  5.373e-05 3.762e-05

So my problem is: why does R say that T0=1979?所以我的问题是:为什么 R 说 T0=1979? This cant be correct as my data starts in 1996 and ends in 2009. When I had a look at the residuals from garch1.1fit, the date is also wrong.这不可能是正确的,因为我的数据从 1996 年开始到 2009 年结束。当我查看 garch1.1fit 的残差时,日期也是错误的。 What's the problem here?这里有什么问题?

I am not sure what object do you use as RV , but I assume it is a numeric vector.我不确定您使用什么对象作为RV ,但我认为它是一个数字向量。 Package rugarch works better with xts objects supported by xts package.包rugarch用更好的作品xts对象通过支持xts包。

Following code should do the job:以下代码应该可以完成这项工作:

require(xts)

time <- #put here time vector from your data
RV.xts <- na.omit(xts(x = RV, order.by = time))

and then your code with changed object RV for new one RV.xts :然后你的代码将对象RV更改为新的RV.xts

garch1.1 <- ugarchspec(variance.model=list(model="sGARCH", garchOrder=c(1,1)),
                       mean.model=list(armaOrder=c(0,0)),
                       distribution="std")
garch1.1fit <- ugarchfit(spec=garch1.1,data=RV.xts)
forecast <- ugarchforecast(garch1.1fit,n.ahead=2)

The code i provided does two things: first it makes an xts object using time .我提供的代码做了两件事:首先它使用time创建一个xts对象。 This object will tell your ugarchfit() function what is the time of this model.这个对象会告诉你的ugarchfit()函数这个模型的时间。 Second, it omits possible NA data, which function ugarchfit() do not handle.其次,它忽略了函数ugarchfit()不处理的可能的 NA 数据。

Make sure if object xts connected dates correctly by checking:通过检查确保对象xts连接日期是否正确:

head(RV.xts)
tail(RV.xts)

I think you did not specify date for your ugarch model.我认为您没有为 ugarch 模型指定日期。 Note that R "Date" class is coded in the number of days from the day 1970-01-01 .请注意,R "Date" 类是以从1970-01-01那天开始的天数编码的。

Following code may help to understand the concept:以下代码可能有助于理解这个概念:

as.Date("1970-01-01")
as.numeric(as.Date("1970-01-01"))

as.Date("1970-01-10")
as.numeric(as.Date("1970-01-10"))

As the date is not specified for ugarch model, your data seems to have the number of observations to fill the 1970-1979 years (probably weekends are excluded), and the prediction starts after that period.由于 ugarch 模型未指定日期,因此您的数据似乎具有填充 1970-1979 年(可能不包括周末)的观察数量,并且预测在该时期之后开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM