Skip to content
Prev 367097 / 398506 Next

object of type 'closure' is not subsettable

Hi.
I tried to run this R-code but still completely no idea why it still gives error message: Error in forecast[[d + 1]] = paste(index(lEJReturnsOffset[windowLength]), ?: object of type 'closure' is not subsettable
Here is the R-code:
library(rugarch); library(sos); library(forecast);library(lattice)library(quantmod); require(stochvol); require(fBasics);data = read.table("EURJPY.m1440.csv", header=F)names(data)data=ts(data)lEJ=log(data)lret.EJ = 100*diff(lEJ)lret.EJ = ts(lret.EJ)lret.EJ[as.character(head(index(lret.EJ)))]=0windowLength=500foreLength=length(lret.EJ)-windowLengthforecasts<-vector(mode="character", length=foreLength)for (d in 0:foreLength) {? lEJReturnsOffset=lret.EJ[(1+d):(windowLength+d)]? final.aic<-Inf? final.order<-c(0,0,0)? for (p in 0:5) for (q in 0:5) {? ? if(p == 0 && q == 0) {? ? ? next? ? }? ??? ? arimaFit=tryCatch(arima(lEJReturnsOffset, order=c(p,0,q)),? ? ? ? ? ? ? ? ? ? ? error=function(err)FALSE,? ? ? ? ? ? ? ? ? ? ? warning=function(err)FALSE)? ? if(!is.logical(arimaFit)) {? ? ? current.aic<-AIC(arimaFit)? ? ? if(current.aic<final.aic) {? ? ? ? final.aic<-current.aic? ? ? ? final.order<-c(p,0,q)? ? ? ? final.arima<-arima(lEJReturnsOffset, order=final.order)? ? ? }? ? } else {? ? ? next? ? }? }
spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1,1)),? ? ? ? ? ? ? ? ? ? ?mean.model = list(armaOrder = c(final.order[1], final.order[3]), arfima = FALSE, include.mean = TRUE),? ? ? ? ? ? ? ? ? ? ?distribution.model = "sged")fit <- tryCatch(ugarchfit(spec, lEJReturnsOffset, solver='gosolnp'),? error=function(e) e, warning=function(w) w)if(is(fit, "warning")) {? forecast[d+1]=paste(index(lEJReturnsOffset[windowLength]), 1, sep=",")? print(paste(index(lEJReturnsOffset[windowLength]), 1, sep=","))} else {? fore = ugarchforecast(fit, n.ahead=1)? ind = fore at forecast$seriesFor? forecasts[d+1] = paste(colnames(ind), ifelse(ind[1] < 0, -1, 1), sep=",")? print(paste(colnames(ind), ifelse(ind[1] < 0, -1, 1), sep=","))?}}write.csv(forecasts, file="forecasts.csv", row.names=FALSE)
??