user2946746
user2946746

Reputation: 1780

getting error "got an unexpected keyword argument 'trend'" with the ARIMA model

I'm not sure why I'm getting this error when trying to run the model when running it in colab. Everything looks correct to me.

import pandas as pd
import yfinance
import matplotlib.pyplot as plt
import statsmodels.api as sm
import numpy as np
tesla_frame = yfinance.Ticker("TSLA").history(start='2020-01-01', end='2022-01-01', interval='1d').reset_index()['Close'].to_frame()
plt.rcParams['figure.figsize'] = [16, 8]
series = tesla_frame['Close']
ar_deg = 4
model = sm.tsa.AutoReg(series, lags=ar_deg, trend='n').fit()
prediction = model.predict()
tesla_frame['Prediction'] = prediction
error_sq = (series - prediction) ** 2
error_sq[error_sq.isna()] = 0

The above works but when I run the ARIMA part I get an error. Code:

garch_model = sm.tsa.ARIMA(error_sq, order=(4,0,3), trend ='c').fit()

Error:

TypeError: new() got an unexpected keyword argument 'trend'

Also:

  arch_model = sm.tsa.ARIMA(error_sq, order=(4,0,0), trend ='c').fit()

Error:

TypeError: new() got an unexpected keyword argument 'trend'

Any idea how to correct this error?

Upvotes: 0

Views: 1037

Answers (1)

Matt Blaha
Matt Blaha

Reputation: 979

I looked up statsmodel's documentation, and I bet your problem is you were reading the docs for a newer version than you had installed.

0.10 did not have the argument "trend":

https://www.statsmodels.org/v0.10.0/generated/statsmodels.tsa.arima_model.ARIMA.html?highlight=arima#statsmodels.tsa.arima_model.ARIMA

It seems it was introduced in 0.11:

https://www.statsmodels.org/v0.11.0/generated/statsmodels.tsa.arima.model.ARIMA.html?highlight=arima#statsmodels.tsa.arima.model.ARIMA

I'd bet you were reading the docs for 0.11 plus but have 0.10 or older installed.

Upvotes: 0

Related Questions