问题
Got an interesting issue with the rugarch package.
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).
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?
Maybe I am going insane...for now I will look further into the documentation that our Alexios has provided
Thanks!
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)
Results
> 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
回答1:
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.
According to the rugarch documentation:
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.
Here is the code:
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),])
A couple of things:
- The variable
i
is used to control which solver is used - 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
- nlminb seems to be the most accurate solver...for this particular dataset
- A common pattern that I am seeing is that the estimate of shape is off by a large margin, except for nlminb
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.
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: 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
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: 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: failed to converge
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
来源:https://stackoverflow.com/questions/51900177/should-the-positioning-of-the-external-regressors-change-the-output-of-arma-garc