python - statsmodels ARMA to predict out-of-sample -
i want predict return of time series, first fitted data set doesn't work when come predict tomorrow's return. code
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 = {} x in range(0,5): 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 , produced error
valueerror: must provide freq argument if no data supplied
i don't understand. had encountered same issue?
i had same issue because index missing freq argument. if print data.index see like
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 'freq = none'
you can :
data = series(data.values, data.index) data = data.asfreq('d')
you can hard specify frequency doing
data.index.freq = 'd'
let me know if helps little.
if not work can use integer prediction , fill index manualy
Comments
Post a Comment