gpt4 book ai didi

python - statsmodels ARMA 来预测样本外

转载 作者:行者123 更新时间:2023-11-30 23:08:17 35 4
gpt4 key购买 nike

我想预测一个时间序列的返回,我首先拟合了数据集,但当我预测明天的返回时它不起作用。我的代码是

    date = datetime.datetime(2014,12,31)
todayDate = (date).strftime('%Y-%m-%d')
startdate = (date - timedelta(days = 1)).strftime('%Y-%m-%d')
enddate = (date + timedelta(days = 2)).strftime('%Y-%m-%d')
data = get_pricing([symbol],start_date= date1, end_date = todayDate, frequency='daily')
df = pd.DataFrame({"value": data.price.values.ravel()},index = data.major_axis.ravel())
result = df.pct_change().dropna()

degree = {}
for x in range(0,5):
for y in range(0,5):
try:
arma = ARMA(result, (x,y)).fit()
degree[str(x) +str(y)] = arma.aic

except:
continue

dic= sorted(degree.iteritems(), key = lambda d:d[1])

p = int(dic[0][0][0])
q = int(dic[0][0][1])
arma = ARMA(result, (p,q)).fit()
predicts = arma.predict()
exogx = np.array(range(1,4))
predictofs = arma.predict(startdate,enddate, exogx)

最后一行不起作用并产生错误

ValueError: Must provide freq argument if no data is supplied

我不明白。有人遇到过同样的问题吗?

最佳答案

我遇到了同样的问题,这是因为您的索引缺少 Freq 参数。如果你打印 data.index 你会看到类似的内容

DatetimeIndex(['2015-06-27', '2015-06-29', '2015-06-30', '2015-07-01', '2015-07-02', '2015-07-03', '2015-07-04', '2015-07-06', '2015-07-07', '2015-07-08', '2015-07-09', '2015-07-10', '2015-07-11', '2015-07-13', '2015-07-14', '2015-07-15', '2015-07-16', '2015-07-17', '2015-07-18', '2015-07-20', '2015-07-21', '2015-07-22', '2015-07-23', '2015-07-24', '2015-07-25', '2015-07-27', '2015-07-28', '2015-07-29', '2015-07-30', '2015-07-31'], dtype='datetime64[ns]', name=u'Date', freq=None)]

注意“Freq = None”

你可以这样做:

data = Series(data.values, data.index)
data = data.asfreq('D')

您还可以通过执行来硬指定频率

data.index.freq = 'D'

请告诉我这是否有帮助。

<小时/>

如果这不起作用,您可以简单地使用整数进行预测,然后手动填充索引

关于python - statsmodels ARMA 来预测样本外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31783141/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com