1
$\begingroup$

I'm currently exploring a couple of statistical forecasting methods. My problem rose when using VARMA(2,1) fixed window rolling forecast. The example code that I'm using is the following: Here I only used 2 series out of 24.

import pandas as pd
from statsmodels.tsa.statespace.varmax import VARMAX

# Parameters
window = 90

# Prepare the two series and train/test split
series_df = dfp[['H0', 'H1']]
n_test     = int(len(series_df) * 0.1)
n_train    = len(series_df) - n_test

test_index = series_df.index[n_train:]
forecasts  = pd.DataFrame(index=test_index, columns=series_df.columns, dtype=float)

# Rolling one‐step‐ahead forecasts using VARMAX(2,1)
for i, dt in enumerate(test_index):
    end        = n_train + i
    start      = end - window
    history_df = series_df.iloc[start:end]

    model = VARMAX(
        history_df,
        order=(2, 1),             # AR=2, MA=1
        trend='c',
        enforce_stationarity=False,
        enforce_invertibility=False
    )
    res = model.fit(maxiter=10, disp=False)

    # forecast returns a DataFrame with one row and two columns
    fc = res.forecast(steps=1)
    forecasts.iloc[i] = fc.iloc[0]

The forecast window size is 90 days, and when applying it to the test set, we talk about 131 1-step-ahead forecasts. For my application it is necessary that I take the full 24-dimensional dataframe.

My question now is, is there a way to speed this up. I'm running it on the 2 series in a colab environment and it takes a minute or so. Using the entire 24 dimensional dataframe, after hours the forecast hasnt been concluded yet. Not only that I tried in Python but also in R too, and encountered the same issue. I also tried to give the VARMAX function a warmstart, by feeding the prior estimates into each new window, also without success. Another question that I have is, I've investigated the internal construction of the VARMAX function of statsmodels, and by default, any VARMA model is internally transferred into a linear state space model. Would it be possible to talk for example the tensorflow tsa libraries, that have a state space model available that runs on GPU and it would lead to the same (or very similar results) ?

Has anyone an idea?

$\endgroup$
4
  • 1
    $\begingroup$ How large is the time series dataframe? $\endgroup$ Commented May 30 at 0:12
  • $\begingroup$ @paisanco, it’s not that large considering I have only a 90day window and 131 (10% of the data) forecasts with re-estimation at each time step. But it is 24-dimensional. $\endgroup$ Commented May 31 at 10:16
  • $\begingroup$ The only VARMA code I could find for Tensorflow is on a Github several years old that may not work with current TensorFLow (have not tried it) github.com/OAID/TensorFlow-HRT/blob/master/tensorflow/contrib/… $\endgroup$ Commented May 31 at 15:55
  • $\begingroup$ @paisanco thank you, I found the same already and couldnt make it run :/ you have any idea why the code i posted takes so much time? Like do you see anything wrong or is there anything that I'm not thinking of ? $\endgroup$ Commented Jun 1 at 12:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.