title: Loop ARIMA combination to minimize RMSE
body: <p><strong>Goal</strong>  : I want to create a loop in R that takes every combination of an ARIMA model on my insample data to get the smallest RMSE when I compare it with the out-of-sample data. </p>
  
  <p><strong>What I have</strong></p>
  
  <p>This is what I have when I do it manually:</p>
  
  <pre><code>#Creating the insample and outsample data 
  insamp &lt;- ts(y[1:48], frequency = 12)
  outsamp &lt;- y[49:60]
  
  #Createing the ARIMA model 
  fit &lt;- Arima(insamp, order = c(1,0,0), include.drift = TRUE)
  
  #forecasting the length of the out of sample data
  fcast2 &lt;- forecast(fit, h=length(outsamp))
  
  #concluding from the RMSE how my model is performing with the out-of-sample data
  accuracy(fcast, outsamp)
                  ME      RMSE      MAE        MPE     MAPE      MASE       ACF1
  Training set 0.2536812  9.158607  6.86326 0.05216278 2.932405 0.3324541 0.01516999
  Test set     8.4465515 26.409409 20.54116 1.20298077 4.552727 0.9950071         NA
  </code></pre>
  
  <p><strong>What i need</strong> </p>
  
  <p>I need a loop that takes every combination of Arima(i,j,k) and compares it to RMSE which the <strong>accuracy</strong> function outputs.  It should provide the outputs of the  (i, j, k) that minimize the RMSE.</p>