<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Dates in timeseries models
Step1:  Getting started
Step2:  Right now an annual date series must be datetimes at the end of the year.
Step3:  Using Pandas
Make a pandas TimeSeries or DataFrame
Step4:  Instantiate the model
Step5:  Out-of-sample prediction
Step6:  Using explicit dates
Step7:  This just returns a regular array, but since the model has date information attached, you can get the prediction dates in a roundabout way.
<ASSISTANT_TASK:>
Python Code:
from __future__ import print_function
import statsmodels.api as sm
import numpy as np
import pandas as pd
Explanation: Dates in timeseries models
End of explanation
data = sm.datasets.sunspots.load()
Explanation: Getting started
End of explanation
from datetime import datetime
dates = sm.tsa.datetools.dates_from_range('1700', length=len(data.endog))
Explanation: Right now an annual date series must be datetimes at the end of the year.
End of explanation
endog = pd.Series(data.endog, index=dates)
Explanation: Using Pandas
Make a pandas TimeSeries or DataFrame
End of explanation
ar_model = sm.tsa.AR(endog, freq='A')
pandas_ar_res = ar_model.fit(maxlag=9, method='mle', disp=-1)
Explanation: Instantiate the model
End of explanation
pred = pandas_ar_res.predict(start='2005', end='2015')
print(pred)
Explanation: Out-of-sample prediction
End of explanation
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)
Explanation: Using explicit dates
End of explanation
print(ar_res.data.predict_dates)
Explanation: This just returns a regular array, but since the model has date information attached, you can get the prediction dates in a roundabout way.
End of explanation
<END_TASK>