Python statsmodels ARIMA Forecast

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.