title: ARIMA Forecasting in R
body: <p>I am trying to implement R forecast function in an online fashion. The idea is to:</p>
  
  <ol>
  <li>train and make predictions for f steps ahead</li>
  <li>observe f outcomes</li>
  <li>re-train and make predictions for f steps ahead</li>
  </ol>
  
  <p>In other words, if, say, f = 5, and we use 20 days to predict days 21 to 25, then use 25 days to predict 26 to 30 etc. This may make a difference. The breakdown of code I have written so far is:   </p>
  
  <p><strong>Packages</strong> </p>
  
  <pre><code>install.packages("quantmod")
  install.packages("forecast")
  
  library(quantmod)
  library(forecast)
  </code></pre>
  
  <p><strong>The data</strong></p>
  
  <pre><code>gspc500&lt;-getSymbols("^GSPC", from = "2000-01-01")
  gspcTail&lt;-diff(log(Cl(GSPC)))
  </code></pre>
  
  <p><strong>Storing vectors</strong></p>
  
  <pre><code>fcasts1&lt;- vector(mode="list", length = 10L) 
  fcasts2&lt;- vector(mode="list", length = 10L)
  fcasts3&lt;- vector(mode="list", length = 10L)
  fcasts4&lt;- vector(mode="list", length = 10L)
  
  fore1&lt;- matrix(NA,ncol=1,nrow=10)
  fore2&lt;- matrix(NA,ncol=1,nrow=10)
  fore3&lt;- matrix(NA,ncol=1,nrow=10)
  fore4&lt;- matrix(NA,ncol=1,nrow=10)
  
  today&lt;- "2016-06-24"
  </code></pre>
  
  <p><strong>The loop</strong></p>
  
  <pre><code>for (i in seq(from = 1, to = 10, by = 1)){
  
  dates&lt;- (seq(as.Date(today), by="days", length=10))
  
  gspcTail1&lt;- as.ts(rbind(cbind(as.xts(dates[i]),fore1[i]),gspc500))
  gspcTail2&lt;- as.ts(rbind(cbind(as.xts(dates[i]),fore2[i]),gspc500))
  gspcTail3&lt;- as.ts(rbind(cbind(as.xts(dates[i]),fore3[i]),gspc500))
  gspcTail4&lt;- as.ts(rbind(cbind(as.xts(dates[i]),fore4[i]),gspc500))
  
  
  win.gspc1&lt;- window(gspcTail1, end=500 + i) 
  win.gspc2&lt;- window(gspcTail2, end=500 + i)
  win.gspc3&lt;- window(gspcTail3, end=500 + i)
  win.gspc4&lt;- window(gspcTail4, end=500 + i)
  
  gspcArma1&lt;-  Arima(win.gspc1, order=c(0,0,0))
  gspcArma2&lt;-  Arima(win.gspc2, order=c(2,0,3))
  gspcArma3&lt;-  Arima(win.gspc3, order=c(1,0,3))
  gspcArma4&lt;-  Arima(win.gspc4, order=c(3,0,3))   
  
  fcasts1[[i]]&lt;- forecast(gspcArma1, h=1)
  fcasts2[[i]]&lt;- forecast(gspcArma2, h=1)
  fcasts3[[i]]&lt;- forecast(gspcArma3, h=1)
  fcasts4[[i]]&lt;- forecast(gspcArma4, h=1)
  
  fore1[i]&lt;-unlist(fcasts1[[i]]$mean[1])
  fore2[i]&lt;-unlist(fcasts2[[i]]$mean[1])
  fore3[i]&lt;-unlist(fcasts3[[i]]$mean[1])
  fore4[i]&lt;-unlist(fcasts4[[i]]$mean[1])  }
  </code></pre>
  
  <p><strong>Issue</strong></p>
  
  <p>The output I am getting for fore(1-4) is incorrect, for one of them it is as follows:</p>
  
  <pre><code>fore1
          [,1]
   [1,]           NA
   [2,]           NA
   [3,]           NA
   [4,]           NA
   [5,] 0.0001503968
   [6,] 0.0001503968
   [7,] 0.0001503968
   [8,] 0.0001503968
   [9,] 0.0001503968
  [10,] 0.0001503968
  </code></pre>
  
  <p>Each fcasts(1-4) value should be added to each gspcTail(1-4). The issue is I don't know how to add obtained forcast(1-4) values at each step to gspcTail(1-4). </p>