# Here is a command to simulate an arima process x <- arima.sim(10000,model=list(ndiff=1,ma=.6)) print(x) ts.plot(x) ## Exponential smoother function expsmooth<-function(series=x,alpha=.5,eps=1e-8,forecast=T){ nobs <- length(x) # Calculate the time lag at which series is said to decay #Estimate alpha from the ARIMA(0,1,1) perspective estarima <- arima.mle(x,model=list(order=c(0,1,1)))$model$ma # Estimate alpha over a grid for(i in 1:9){ alphatemp <- .36 + i/100 decaylength <- ceiling(log(eps/alphatemp)/log(1 - alphatemp)) runningsum <- 0 for(j in 1:(nobs-decaylength-1)){ pred <- sum(x[j:(j+decaylength)] * alphatemp * (1 - alphatemp)^c((decaylength):0)) runningsum <- runningsum + (pred - x[j + decaylength + 1])^2 } print(runningsum) } return(c(nobs,decaylength,estarima)) } expsmooth(x)