关于rugarch软件包有一个有趣的问题。
我注意到,当我更改外部回归器的顺序时,健壮系数矩阵的值会有所不同。值应相同(与变量的顺序有关)。但是,我得到的结果截然不同。当时的模型是arma(2,2)+ garch(1,0)。
这被认为是rugarch包装的正常行为吗?
我认为,当您更改外部回归器的顺序时,输出应该是相同的(根据回归器的顺序)。
我通过创建可以由任何人测试的通用脚本来确认此问题。有人遇到过这个问题吗?或者是否有描述我所面临问题的帖子?
也许我疯了……现在,我将进一步研究Alexios提供的文档
谢谢!
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
答案 0 :(得分:0)
更新: 因此,我通过r-sig-finance与Alexios联系,但我忘了包含fit.control ...一个不容错过的重要参数!但是,经过进一步检查,我发现求解器产生了一些有趣的结果。
根据rugarch文档:
“混合”策略求解器首先尝试“ solnp”求解器, 未能收敛,然后尝试“ nlminb”,“ gosolnp”和 最后是“ nloptr”求解器。
所以我做了一个快速测试来检查每个求解器。
代码如下:
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),])
几件事:
i
用于控制使用哪个求解器结果:对于每个求解器,我基本上都采用了两个矩阵的差值,以了解它们之间的差异。然后,我总结了这些差异。结论后显示结果。请注意,由于混合策略在策略中首先使用了solnp,因此其结果与solnp相同。
结论: 如文档中所述,混合策略使用solnp。该求解器不会收敛。但是,如果您注意到两个模型之间的差异,则它们会很大。看一下solnp和hybrid之间的结果。
solnp:差异之和= -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
# 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
# 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: 无法收敛
nloptr:差异之和= 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