简体   繁体   English

statsmodels ARMA预测样本外

[英]statsmodels ARMA to predict out-of-sample

I want to predict the return of a time series, I first fitted the data set but it doesn't work when I come to predict the tomorrow's return. 我想预测时间序列的返回,我首先拟合数据集但是当我预测明天的回报时它不起作用。 My code is 我的代码是

    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)

The last line doesn't work and it produced an error 最后一行不起作用,它产生了一个错误

ValueError: Must provide freq argument if no data is supplied ValueError:如果未提供数据,则必须提供freq参数

I don't understand. 我不明白。 Anyone had encountered the same issue? 有人遇到过同样的问题吗?

I had the same issue it is because your index is missing the Freq argument. 我遇到了同样的问题,因为你的索引缺少Freq参数。 If you print data.index you will see that something like 如果你打印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)] 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)]

Note the 'Freq = None' 注意'Freq = None'

you can do something like : 你可以这样做:

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

You can also hard specify frequency by doing 您也可以通过执行来硬指定频率

data.index.freq = 'D'

Let me know if that helps a little. 如果这有点帮助,请告诉我。


If that does not work you can simply use the integer to do the prediction and then fill the index manualy 如果这不起作用,您可以简单地使用整数来进行预测,然后手动填充索引

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用statsmodels进行ARMA样本外预测 - ARMA out-of-sample prediction with statsmodels statsmodels:使用公式可提供给result.predict()的样本外预测的允许格式是什么 - statsmodels: What are the allowable formats to give to result.predict() for out-of-sample prediction using formula Statsmodels OLS get_prediction 对样本外数据 - Statsmodels OLS get_prediction on out-of-sample data 返回StatsModel中样本外预测的标准和置信区间 - Return std and confidence intervals for out-of-sample prediction in StatsModels 在 Statsmodels -python 中使用 SARIMAX 预测具有外生变量的样本外 - Forecasting out-of-sample with exogenous variables using SARIMAX in Statsmodels -python Statsmodels“预测”功能 - 为什么我不能预测样本外? :( - Statsmodels "predict" function - why cant I predict out of sample? :( 使用 Statsmodels -python 中的时变回归示例代码预测具有外生变量的样本外 - Forecasting out-of-sample with exogenous variables using Time-varying regression example code in Statsmodels -python Python中的Statsmodels包 - 检索ARIMA模型的样本外预测的问题 - Statsmodels package in Python - issues with retrieving out-of-sample prediction of ARIMA model python statsmodels ARMA plot_predict - python statsmodels ARMA plot_predict 如何使用 statsmodels 的 ARMA 来预测外生变量? - How to use statsmodels' ARMA to predict with exogenous variables?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM