I am trying to do out of sample forecasting using python statsmodels. I do not want to just forecast the next x number of values from the end of the training set but I want to forecast one value at a time and take in consideration the actual values when forecasting. In other words I want to do rolling 1-period forecasts, but I don't want to recalibrate the model every time. The closest post I could find was here:
ARMA out-of-sample prediction with statsmodels
However, this uses ARMA not ARIMA. How can I achieve this with ARIMA or is there a better method? I know I could actually pull the coefficients and apply a function myself but in my code the ARIMA model I am using is dynamic over time, therefore the number of coefficients and lagged values used is not constant. Any help would be greatly appreciated.
If I am right, I had the very similar problem: basically I wanted to split my time series into training and test set, train the model, and then predict arbitrarily any element of the test set given its past history. I did not manage to achieve it using the ARIMA statsmodels class though.
That's how I did it using statsmodels: I've applied a first order difference to the series to achieve stationarity, and computed an arma model:
model = sm.tsa.ARMA(fitting_data, order=(p, q), dates=fitting_dates).fit()
I've converted the arma model into a pure-ar one:
ar_params = model.arparams
ma_params = model.maparams
ar_coefficients = arma2ar(ar_params, ma_params, nobs=final_ar_coeff)
The nobs parameters influences the number of auto-regressive coefficients you will get. I tried several values, increasing it until no significant change in the predictions was observed. Once you get your predictions w.r.t. the differenced series, you want to bring back them to the original one. I implemented a method which, given one or a chain of predictions and the last known element before your forecasts, computes the predictions in the original series:
def differenced_series_to_original(values, starting_value):
original_series = [starting_value]
[original_series.append(original_series[-1]+i) for i in values]
return original_series[1:]
Obviously values is the list of your predictions, starting_value the last known element. Hope it helps with your problem.