> Error in forecast[[d + 1]] = paste(index(lEJReturnsOffset[windowLength]),  : 
> object of type 'closure' is not subsettable

A 'closure' is a function and you cannot use '[' or '[[' to make a
subset of a function.

You used
   forecast[d+1] <- ...
in one branch of the 'if' statement and
   forecasts[d+1] <- ...
in the other.  Do you see the problem now?

By the way, the code snippet in the error message says '[[d+1]]' but
the code you supplied has '[d+1]'.  Does the html mangling selectively
double brackets or did you not show us the code that generated that
message?

Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Sun, Feb 12, 2017 at 4:34 AM, Allan Tanaka <allantanak...@yahoo.com> wrote:
> 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)      }    } els!
 e {      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@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)
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to