Suppose that I have the following "for" loop in R:
USDlogreturns=diff(log(prices))
for(p in 0:1) for(q in 0:1){
model<-ugarchspec(variance.model = list(model="fGARCH", submodel = "GARCH", garchOrder = c(1, 1)),mean.model = list(armaOrder = c(p, q), include.mean = TRUE), distribution.model = "norm")
modelfit<-ugarchfit(spec=model, data=USDlogreturns, solver="hybrid")
}
What is the proper command to store the four models' coefficients in a matrix? I already tried to build the command based on an answer to a previous post (see link: Loop for ARMA model estimation) but was not able to obtain the expected result for the above loop.
EDIT:
The following "pseudo-code" is wrong in that it does not store the omega, alpha1 and beta1 coefficients in the third, fourth, and fifth columns of the coefficient matrix.
Can anyone help me find out and correct the error?
Pseudo-code:
armagarchcoefmat=matrix(NA, 4, 6)
a=0
for(p in 0:1) for(q in 0:1){
a=a+1
model<-ugarchspec(variance.model = list(model="fGARCH", submodel = "GARCH", garchOrder = c(1, 1)),mean.model = list(armaOrder = c(p, q), include.mean = TRUE), distribution.model = "norm")
modelfit<-ugarchfit(spec=model, data=USDlogreturns, solver="hybrid")
if(p>0) armagarchcoefmat[a, c(1: p) ]=coef(modelfit)[2:6][c( 1 : p )]
if(q>0) armagarchcoefmat[a, c(2:(1+q))]=coef(modelfit)[2:6][c((p+1):(p+q))]
armagarchcoefmat[a, 6 ]=head(coef(modelfit),1)
}