from __future__ import print_function import statsmodels.api as sm import numpy as np import pandas as pd
Right now an annual date series must be datetimes at the end of the year.
from datetime import datetime dates = sm.tsa.datetools.dates_from_range('1700', length=len(data.endog))
Make a pandas TimeSeries or DataFrame
Instantiate the model
ar_model = sm.tsa.AR(endog, freq='A') pandas_ar_res = ar_model.fit(maxlag=9, method='mle', disp=-1)
Out-of-sample prediction
ar_model = sm.tsa.AR(data.endog, dates=dates, freq='A') ar_res = ar_model.fit(maxlag=9, method='mle', disp=-1) pred = ar_res.predict(start='2005', end='2015') print(pred)
This just returns a regular array, but since the model has date information attached, you can get the prediction dates in a roundabout way.
Note: This attribute only exists if predict has been called. It holds the dates associated with the last call to predict.
© 2009–2012 Statsmodels Developers
© 2006–2008 Scipy Developers
© 2006 Jonathan E. Taylor
Licensed under the 3-clause BSD License.
http://www.statsmodels.org/stable/examples/notebooks/generated/tsa_dates.html