Rolling Window Forecasts in R I have a question: how do I use rolling window forecasts in R:
I have 2 datasets: 


*

*monthly data which I downloaded from Google. 

*monthly data I downloaded from the CBS (central bureau of statistics in Holland)


I want to test whether I can build a valid forecasting model, based on say 6years of Google Data, by using rolling window forecasts.
My first intuition was to fit an ARIMA model on the Google Data and test this model on the actual CBS data by calculating the RMSE. But this is not efficient since I need to do this for every month, and I have a lot of months to analyse. 
Is there an automated way in R to do this?
 A: I have had same situation and the following R code solved my problem. Although I was using linear regression (lm), you can replace it with ARIMA if you want. 
dd          <- read.csv("SCALE8_data_ready_4_BN_exp1.csv")
windowsSize <- 4000  # training data size
testsize    <- 70    # number of observation to forecast
# load variables from the data set 
delta1      <- dd$delta_t_discrete_3  #$
OSVOS1      <- dd$OSV_OS_discrete     #$
nbAlpha1    <- dd$nb_alpha_corrected  #$
OSVEXT1     <- dd$OSVEXT              #$
h1          <- dd$hidden_state        #$
RMSE        <- matrix(0,50,1)
for(k in 0:33)  # run 34 experiments
{
  A         <- k*testsize + 1
  B         <- A + windowsSize - 1
  start_obs <- A
  end_obs   <- B

  delta     <- delta1[A:B]
  NbAlpha   <- nbAlpha1[A:B]
  OSVOS     <- OSVOS1[A:B]
  OSVEXT    <- OSVEXT1[A:B]

 # ddata    <- data.frame(delta=delta, NbAlpha=NbAlpha, OSVOS=OSVOS, OSVEXT=OSVEXT)
 # output   <- paste("Gold_theta0.2per_alpha_0.1_CPTs_from", A, "to", B, 
 #                   "RollingLMTraining.csv")
 # write.csv(ddata, file=output)

  llmm       <- lm( OSVEXT~delta + NbAlpha + OSVOS)  # initiate linear regression
  intercept  <- coef(llmm)[1]
  co_delta   <- coef(llmm)[2]
  co_NbAlpha <- coef(llmm)[3]
  co_OSVOS   <- coef(llmm)[4]


  A           <- B + 1
  B           <- B + testsize
  delta       <- delta1[A:B]
  NbAlpha     <- nbAlpha1[A:B]
  OSVOS       <- OSVOS1[A:B]
  OSVEXT      <- OSVEXT1[A:B]
  predict_EXT <- matrix(0, testsize, 1)
  SSE         <- 0
  for(i in 1:testsize)  # do the forecast based on LM results
  {
    predict_EXT[i] <- intercept + delta[i]*co_delta + NbAlpha[i]*co_NbAlpha + 
                      OSVOS[i]*co_OSVOS
    SSE <- SSE + (predict_EXT[i] - OSVEXT[i])^2
  }
  RMSE[k+1] <- sqrt(SSE/testsize)
 # ddata    <- data.frame(Predicted_EXT=predict_EXT, Real_OSVEXT=OSVEXT)
 # output   <- paste("from", A, "to", B, "RollingLMTesting.csv")
 # write.csv(ddata, file=output)
 print(RMSE[k+1])

}

