#!/usr/bin/env python
# coding: utf-8

get_ipython().run_line_magic('matplotlib', 'inline')
import pandas as pd
import pandas_datareader
import matplotlib.pylab as plt
import seaborn as sns
from matplotlib.pylab import style
from statsmodels.tsa.arima_model import ARIMA
from statsmodels.graphics.tsaplots import plot_acf,plot_pacf

style.use('ggplot')
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

stockFile = 'F:/work/resource/data/T10yr.csv'
stock = pd.read_csv(stockFile,index_col=0,parse_dates=[0])
stock.head(5)
#stock.tail(5)

stock_week = stock['Close'].resample('W-MON').mean()
stock_train = stock_week['2000':'2015']

model = ARIMA(stock_train,order=(1,1,1),freq='W-MON')
result = model.fit()

pred = result.predict('2001','2017',dynamic=True,typ='levels')
pred

plt.figure(figsize=(6,6))
plt.xticks(rotation=45)
plt.plot(stock_week)
plt.plot(pred)

help(pred)
