外部回归器的位置是否应该改变arma-garch的输出? (可能的rugarch错误/错误) [英] Should the positioning of the external regressors change the output of arma-garch? (Possible rugarch bug/error)

查看:147
本文介绍了外部回归器的位置是否应该改变arma-garch的输出? (可能的rugarch错误/错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于rugarch软件包有一个有趣的问题.

Got an interesting issue with the rugarch package.

我注意到,当我更改外部回归器的顺序时,健壮系数矩阵的值会有所不同.值应相同(取决于变量的顺序).但是,我得到的结果截然不同.当时的模型是arma(2,2)+ garch(1,0).

I noticed that when I changed the order of the external regressors, there are different values for the robust coefficient matrix. The values should be the same (respective to the ordering of the variables). However, I am getting drastically different results. At that time the model was arma(2,2) + garch(1,0).

这被认为是rugarch包装的正常行为吗?

Is this considered a normal behavior of the rugarch package?

我假设当您更改外部回归器的顺序时,输出应该是相同的(根据回归器的顺序).

I assume that when you change the ordering of the external regressors the output should be the same (according to the order of the regressors) ....digit by digit.

我通过创建可以被任何人测试的通用脚本来确认了此问题.是否有人之前曾遇到此问题,或者是否有描述我所面临问题的帖子?

I confirmed this issue by creating a generic script that can be tested by anyone. Has anybody faced this issue before or is there post that describes the issue that I am facing?

也许我疯了……现在,我将进一步研究Alexios提供的文档

Maybe I am going insane...for now I will look further into the documentation that our Alexios has provided

谢谢!

library(rugarch) 

set.seed(1) 

x1 <- rnorm(1000,5,1) 
x2 <- rnorm(1000,3,3) 

y    <- .5*(x1*x2) + rnorm(1000,1,3) 
dat  <- data.frame(x1,x2,y) 

var1 <- c("x1","x2") 
var2 <- c("x2","x1") 

# setbounds(spec)<-list(vxreg1=c(-1,1)) 
model_maker <- function(x_name){ 
  temp <- dat[,c("y",x_name)] 

  spec <- ugarchspec(variance.model      = list(model = "sGARCH", 
                                                garchOrder = c(1,0)), 

                     mean.model          = list(armaOrder = c(2,2), 
                                                external.regressors = as.matrix(temp[,x_name]), 
                                                include.mean= T), 

                     distribution.model  = "std") 

  fit         <- ugarchfit(spec = spec, data = as.matrix(temp$y),solver = "hybrid") 
  return(fit@fit$robust.matcoef)} 

model_maker(var1) 
model_maker(var2)

结果

> model_maker(var1)
                     Estimate            Std. Error                t value           Pr(>|t|)
mu     -7.538187403788707e+00 8.786973516670712e-02 -8.578821125939666e+01 0.0000000000000000
ar1     4.486422838091979e-01 6.673242425241943e-03  6.723002930512180e+01 0.0000000000000000
ar2     5.509436808922650e-01 8.689261995135296e-03  6.340511785704150e+01 0.0000000000000000
ma1    -4.229313469721094e-01 9.904526629376784e-05 -4.270081375900357e+03 0.0000000000000000
ma2    -5.909394433456913e-01 5.328845280848644e-05 -1.108944644104175e+04 0.0000000000000000
mxreg1  1.636837420433226e+00 1.860043860817216e-02  8.799993671730280e+01 0.0000000000000000
mxreg2  2.497594073093352e+00 2.935374105837549e-02  8.508605659927339e+01 0.0000000000000000
omega   1.204434970615901e+01 1.164871508782470e+00  1.033963799041478e+01 0.0000000000000000
alpha1  3.088952958748960e-09 7.706257096572960e-05  4.008369977849096e-05 0.9999680178348154
shape   2.264515398950677e+01 1.626608738905429e+02  1.392169699318415e-01 0.8892786990201700
> model_maker(var2)
                     Estimate            Std. Error                t value           Pr(>|t|)
mu     -7.877119924850585e+00 1.468654041377859e-02 -5.363495896869247e+02 0.0000000000000000
ar1     6.599347321880189e-01 1.052007357763227e-03  6.273099967581684e+02 0.0000000000000000
ar2     3.429324065506440e-01 7.290845959665856e-04  4.703602413873531e+02 0.0000000000000000
ma1    -6.161353098757911e-01 2.172817763786096e-05 -2.835651107721921e+04 0.0000000000000000
ma2    -3.961541217693775e-01 2.673334524811993e-06 -1.481872612995329e+05 0.0000000000000000
mxreg1  2.498594649158790e+00 4.725354999748145e-03  5.287633731840174e+02 0.0000000000000000
mxreg2  1.686570324631110e+00 3.061281186945296e-03  5.509361021207126e+02 0.0000000000000000
omega   1.177846519677343e+01 6.508282352389305e-01  1.809765550882921e+01 0.0000000000000000
alpha1  1.132843707658519e-06 5.435981230642132e-05  2.083972809311375e-02 0.9833735061770428
shape   1.352084437533810e+01 1.837896072265797e+01  7.356696920663922e-01 0.4619317385213701

推荐答案

更新: 因此,我通过r-sig-finance与Alexios联系,但我忘了包含fit.control ...一个不容错过的重要参数!但是,在进一步检查后,我发现求解器产生了一些有趣的结果.

UPDATE: So I contacted Alexios, through r-sig-finance and I forget to include fit.control... an important parameter not to be missed! However, upon further inspection I found some interesting results with the solvers.

根据rugarch文档:

According to the rugarch documentation:

混合"策略求解器首先尝试"solnp"求解器, 未能收敛,然后尝试"nlminb","gosolnp"和 最后是"nloptr"求解器.

The "hybrid" strategy solver first tries the "solnp" solver, in failing to converge then tries then "nlminb", the "gosolnp" and finally the "nloptr" solvers.

所以我做了一个快速测试来检查每个求解器.

So I did a quick test to check each solver.

这是代码:

library(rugarch) 
library(rugarch) 

set.seed(1) 

x1 <- rnorm(1000,5,1) 
x2 <- rnorm(1000,3,3) 

y    <- .5*(x1*x2) + rnorm(1000,1,3) 
dat  <- data.frame(x1,x2,y) 

var1   <- c("x1","x2") 
var2   <- c("x2","x1") 
solver <- c("solnp","hybrid","nlminb","lbfgs","nloptr")

# setbounds(spec)<-list(vxreg1=c(-1,1)) 
model_maker <- function(x_name,solver){ 
  temp <- dat[,c("y",x_name)] 

  spec <- ugarchspec(variance.model      = list(model = "sGARCH", 
                                                garchOrder = c(1,0)), 

                     mean.model          = list(armaOrder = c(2,2), 
                                                external.regressors = as.matrix(temp[,x_name]), 
                                                include.mean= T), 

                     distribution.model  = "std") 

  fit         <- ugarchfit(spec = spec, data = as.matrix(temp$y),solver = solver, fit.control=list(scale=1)) 
  return(fit@fit$robust.matcoef)} 
i=1
model1 <- model_maker(var1,solver[i]) 
model2 <- model_maker(var2,solver[i])

# Print the results
model1
model2

# Calculate the differences, note that the result is in the correct order, meaning that mxreg1 represents variable x1 
model1 - model2[c(1:5,7,6,8:10),]
sum(model1 - model2[c(1:5,7,6,8:10),])

几件事:

  1. 变量i用于控制使用哪个求解器
  2. 我没有运行gosolnp,因为这将花费我一些时间来理解如何正确使用它...我计划稍后再弄乱它
  3. 对于特定的数据集,
  4. nlminb似乎是最准确的求解器...
  5. 我看到的一个常见模式是,除了nlminb以外,形状的估计值有很大的偏差
  1. The variable i is used to control which solver is used
  2. I did not run the gosolnp because that will take time for me to understand how to use it properly...I plan on messing around with it later
  3. nlminb seems to be the most accurate solver...for this particular dataset
  4. A common pattern that I am seeing is that the estimate of shape is off by a large margin, except for nlminb

结果:对于每个求解器,我基本上都采用了两个矩阵的差值,以了解它们之间的差异.然后,我总结了这些差异.结论后显示结果.请注意,由于混合策略在策略中首先使用了solnp,因此其结果与solnp相同.

Results: For each solver, I basically took the difference of the two matrices to see how different they were. I then took the sum of those differences. The results are shown after the conclusion. Note that hybrid gives the same result as solnp because it uses solnp first in it's strategy.

结论: 如文档中所述,混合策略使用solnp.该求解器不会收敛.但是,如果您注意到两个模型之间的差异,则它们会很大.看一下solnp和hybrid之间的结果.

Conclusion: As stated in the documentation, the hybrid strategy uses solnp. This solver does not fail to converge. However, if you notice the differences between the two models, they are quite large. Take a look at the results between solnp and hybrid.

solnp:差异之和= -322573094

solnp: sum of differences = -322573094

#           Estimate    Std. Error       t value      Pr(>|t|)
# mu      1.738126e-01 -6.823128e-01 -2.014060e+04  0.000000e+00
# ar1    -1.563344e+00 -8.188160e-03 -1.280088e+02  5.132347e-01
# ar2     1.955544e+00 -7.682856e-03  1.155578e+03  0.000000e+00
# ma1     1.537478e+00 -1.268071e-02 -9.338894e+01  0.000000e+00
# ma2    -1.933255e+00 -1.065511e-05 -3.225948e+08  0.000000e+00
# mxreg1 -8.917738e-02 -1.263512e-01  2.067577e+04  0.000000e+00
# mxreg2 -8.266427e-03 -4.321936e-02  2.033637e+04  0.000000e+00
# omega   1.866515e-02  9.641896e-03 -4.654283e-01  0.000000e+00
# alpha1  2.971507e-12  5.501971e-06  1.915043e-07 -1.527983e-07
# shape  -2.869267e+01 -2.406363e+01  1.578825e+00 -8.739897e-02

混合:差异总和= -322573094

hybrid: sum of differences = -322573094

#            Estimate    Std. Error       t value      Pr(>|t|)
# mu      1.738126e-01 -6.823128e-01 -2.014060e+04  0.000000e+00
# ar1    -1.563344e+00 -8.188160e-03 -1.280088e+02  5.132347e-01
# ar2     1.955544e+00 -7.682856e-03  1.155578e+03  0.000000e+00
# ma1     1.537478e+00 -1.268071e-02 -9.338894e+01  0.000000e+00
# ma2    -1.933255e+00 -1.065511e-05 -3.225948e+08  0.000000e+00
# mxreg1 -8.917738e-02 -1.263512e-01  2.067577e+04  0.000000e+00
# mxreg2 -8.266427e-03 -4.321936e-02  2.033637e+04  0.000000e+00
# omega   1.866515e-02  9.641896e-03 -4.654283e-01  0.000000e+00
# alpha1  2.971507e-12  5.501971e-06  1.915043e-07 -1.527983e-07
# shape  -2.869267e+01 -2.406363e+01  1.578825e+00 -8.739897e-02

nlminb:差异之和= 0.004690549

nlminb: sum of differences = 0.004690549

#           Estimate    Std. Error       t value      Pr(>|t|)
# mu      8.334588e-06 -6.810307e-07  1.505486e-06  0.000000e+00
# ar1     8.212314e-06 -1.753588e-06  1.858127e-04 -3.444543e-08
# ar2    -1.410239e-06 -1.691983e-06 -3.677855e-04  0.000000e+00
# ma1    -8.903242e-06 -2.680788e-06 -2.087611e-04 -5.599837e-07
# ma2    -6.084540e-07  1.463211e-06 -2.847722e-04  0.000000e+00
# mxreg1 -1.707573e-06 -2.549609e-07  1.286915e-05  0.000000e+00
# mxreg2 -1.228276e-07 -1.125697e-08  1.254835e-05  0.000000e+00
# omega   4.556487e-06  1.505588e-04 -2.618454e-03  0.000000e+00
# alpha1  0.000000e+00  2.212422e-05  0.000000e+00  0.000000e+00
# shape   9.509008e-04  6.844028e-03 -3.480029e-05  2.262813e-05

lbfgs: 无法收敛

lbfgs: failed to converge

nloptr:差异之和= 9.937713

nloptr: sum of differences = 9.937713

#             Estimate    Std. Error      t value     Pr(>|t|)
# mu     -0.0057978361 -1.525932e-04 -0.010722941  0.000000000
# ar1     0.0007429396 -1.984846e-02 -0.018458177 -0.009827180
# ar2     0.0010449391 -7.694273e-03 -0.017611750 -0.008069019
# ma1    -0.0007444894 -1.894543e-02  0.019331928 -0.009721757
# ma2    -0.0007670455 -7.811075e-03  0.021252924 -0.008391716
# mxreg1  0.0013125601 -2.700489e-05  0.012942836  0.000000000
# mxreg2  0.0000503455 -5.738682e-06  0.008939747  0.000000000
# omega  -0.0003911163 -1.940285e-04  0.002957193  0.000000000
# alpha1  0.0000000000 -3.453686e-05  0.000000000  0.000000000
# shape   1.0873917654  8.931931e+00 -0.017380270  0.012411900

这篇关于外部回归器的位置是否应该改变arma-garch的输出? (可能的rugarch错误/错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆