2

i'm working on SARIMAX model to predict stock market in python. I divided the data to training and testing data. After fitting my model on the training data, my goal is to predict the testing data (one step prediction)

When i add exogs to the model, it returns very accurate results, however, when i fit the model without exogs I got a straight line. I went throw some similar questions but i couldn't solve the problem. This is my code:

fitting the model

`mod1 = sm.tsa.statespace.SARIMAX(endog= ptrain,
                            exog = ftrain,
                            order=(1, 1, 0),
                            seasonal_order=(0, 0, 0, 12),
                            enforce_stationarity=False,
                            enforce_invertibility=False)
results1 = mod1.fit()`

Out of sample prediction

`prediction=results1.get_prediction(start=pd.to_datetime(ptrain.index[-1]),end=pd.to_datetime(ptest.index[-1]),exog= test)

` This is the plot i got[1]: https://i.stack.imgur.com/XDd6n.png

Any idea on how to do the prediction properly?

K A
  • 21
  • 3
  • Do you know how to do multistep forecasting (like a year)? I have a training and test-set, but I struggle to make it forecast on my test-set – CutePoison Sep 03 '20 at 16:17

1 Answers1

0

Since you have set stationarity enforcement and invertibility enforcement to False, you are likely to achieve an unreliable forecast. You can very well try a search for the best paramaters for (p,d,q) and (P,D,Q)s by trying something of a below nature:

for ...:
  try:
    model = smt.SARIMAX(...)
    result = model.fit()
    ...
  except:
    continue
asimo
  • 2,340
  • 11
  • 29