I am working on a time series whose values are strictly positive. However, in some cases when the values are near zero, the forecast also takes negative values.

Is there a way to tell to the Python statsmodel package to stay positive?

Example of the code I am using now:

mod = sm.tsa.statespace.SARIMAX(y,
                                order = pdq,
                                seasonal_order = seasonal_pdq,
results = mod.fit()

The classical way to ensure that forecasts stay positive is to take logarithms of the original series, model these, forecast, and transform back. This is a specific case of the more general Box-Cox transform.

Be aware that you can't just backtransform by taking exponentials, since this will introduce a bias - the exponentiated forecasts will be too low. You need to adjust the backtransformation using the residual variance.

Alternatively, you can of course always truncate forecasts from below.


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.