简体   繁体   English

在R中拟合GARCH模型

[英]Fitting a GARCH model in R

I am trying to fir different GARCH models in R and compare them through the AIC value(the minimum one being the best fit). 我正在尝试在R中生成不同的GARCH模型,并通过AIC值(最小的是最合适的)比较它们。 I have used a dataset and taken out the AIC through two methods. 我使用了数据集,并通过两种方法取出了AIC。

Method 1: I took the data set for stock prices(closing data for s&p cnx nifty from 4 Jan 2010 to 9 Nov 2016, daily),took the log and then the difference and then through auto arima(on the difference of log values, let's call the data set as A) found out that the best fit is MA1 and then gotten the residuals' square using 方法1:我获取了股票价格数据集(从2010年1月4日到2016年11月9日,s&p cnx nifty的收盘数据,每天),先记录日志,然后取差价,然后通过自动有价证券(关于对数值的差,我们将数据集称为A),发现最佳拟合为MA1,然后使用

Res2<- (MA1$residuals)^2

In method one, I have used the syntax 在方法一中,我使用了语法

garchoutput <- garch(Res2,order=c(1,1))
  CIC<-AIC(garchoutput)

It gives me an AIC value of -23682.50 . 它的AIC值为-23682.50。 Used package 'tseries' for the same. 使用了相同的软件包“ tseries”。

Method 2: I used another package namely 'rugarch' and then used the below syntax 方法2:我使用了另一个包“ rugarch”,然后使用以下语法

spec <- ugarchspec(variance.model = list( garchOrder = c(1, 1), 
                                     submodel = NULL, 
                                     external.regressors = NULL, 
                                     variance.targeting = FALSE), 

               mean.model     = list(armaOrder = c(0, 1), 
                                     external.regressors = NULL, 
                                     distribution.model = "norm", 
                                     start.pars = list(), 
                                     fixed.pars = list()))

garch <- ugarchfit(spec = spec, data = A, solver.control = list(trace=0))
garch

Here the data I put it in A and the model itself fits in GARCH(1,1) with ARIMA90,0,1) ie, MA1. 在这里,我将数据放在A中,并且模型本身适合ARIMA90,0,1)(即MA1)的GARCH(1,1)。

The output I receive has a lot of data but it also has the AIC value 我收到的输出有很多数据,但也有AIC值

方法2的输出

What I want to enquire is as to why there is the difference in the two values. 我想问的是为什么两个值存在差异。 Also, if someone could also explain to me how the package fgarch can be used instead of rugarch and the difference between the two, it will be highly beneficial. 另外,如果有人可以向我解释如何使用fgarch软件包代替rugarch以及两者之间的区别,那将是非常有益的。

Please let me know incase it is difficult to do the analysis because of the data availability. 如果由于数据可用性而难以进行分析,请告知我。 Apologies if the question is not properly framed. 如果问题的框架不正确,我们深表歉意。

This is maybe a bit late but this has been asked and answered on Cross Validated a while ago in this post or this post . 这也许是有点晚了,但是这已经被问和前一阵子在回答关于跨验证这个帖子这个职位

To summarize the above mentioned answers: 总结上述答案:

Some packages (eg fgarch , rugarch or rmgarch ) use a scaled version of the AIC, which is is basically the "normal" AIC divided by the length of the time series (usually denoted by n or N ). 一些软件包(例如fgarchrugarchrmgarch )使用AIC的缩放版本,该版本基本上是“正常” AIC除以时间序列的长度(通常由nN表示)。

For the rugarch package you can see the specification of the AIC here on page 23 . 对于rugarch软件包,您可以在此处第23页上看到AIC的规范。

For your specific example you can compare the two by either: 对于您的特定示例,您可以通过以下任一方式将两者进行比较:

  • multiplying the AIC from rugarch with the length of your time-series AIC从rugarch 乘以时间序列的长度

    or 要么

  • divide the AIC from the tseries with the length of your time-series, like: AIC从tseries系列中除以时间序列的长度,例如:

     CIC = AIC(garchoutput)/length(Res2) 

One more thing. 还有一件事。 As far as I know you don't need to square the residuals from your fitted auto.arima object before fitting your garch-model to the data. 据我所知,在将auto.arima模型拟合到数据之前,不需要对拟合的auto.arima对象的残差求平方。 You might compare two very different sets of data if you use squared reisiduals in your tseries model and your log-returns in the rugarch model. 如果您在使用方reisiduals你可能会比较两个非常不同的数据集的tseries机型,并在您的登录回报rugarch模型。

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

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