0
$\begingroup$

I am trying to run some ARIMA forecasts and I switched recently from R to Python.

I am struggling for some reason to make this series stationary .

I try to take the log returns of stock prices as such :

$$ ret = \ln{\frac{P_{i}}{P_{i-1}}}$$

I am using this line in Python:

[x for x in np.log(df.price/df.price.shift(-1)) if str(x) != 'nan']

see the first observations in the data

          date         price    logret  fcast
0    2020-08-03  11823.690000  0.041427    0.0
1    2020-08-02  11343.880000  0.020389    0.0
2    2020-08-01  11114.930000  0.001104    0.0
3    2020-07-31  11102.670000  0.015222    0.0

the adFuller test returns :

adfuller(df.logret)
(-17.0273775639977, 8.372792842473242e-30, 1, 578, {'1%': -3.441714324024304, '5%': -2.8665533998436215, '10%': -2.5694399997605393}, -1971.579460294467)

from my understanding this series should be stationary.

But when I run a for loop to generate the ARIMA grid I get a weird error telling me that series is not stationary.

AR/MA(5,5)

ERROR Example: 
HessianInversionWarning: Inverting hessian failed, no bse or cov_params available
  warn('Inverting hessian failed, no bse or cov_params '

AR/MA(10,10)

Another ERROR : 

ValueError: The computed initial MA coefficients are not invertible
You should induce invertibility, choose a different model order, or you can
pass your own start_params.
$\endgroup$
  • $\begingroup$ it's hard to know what the problem might be without being able to re-run your code ourselves - can you add a snippet that reproduces the above error? Right now, it could be a data problem, a data wrangling problem, a code problem, or a numerical problem... $\endgroup$ – StackG Aug 3 at 0:49
3
$\begingroup$

Your shift is in the wrong direction.

Do this:

df.price = pd.to_numeric(df.price)
df['logret'] = np.log(df.price/df.price.shift(1))    
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.