码迷,mamicode.com
首页 > 其他好文 > 详细

Canadian-dollar_RMB

时间:2018-12-31 13:55:39      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:git   graphic   for   code   hung   port   nts   xls   plt   

import pandas as pd
import matplotlib.pyplot as plt
import statsmodels as sm
from statsmodels.graphics.tsaplots import plot_acf,plot_pacf
import numpy as np
discfile = r‘C:\Users\GitHung Zeng\Documents\WeChat Files\WT13662535567\Files\日线数据\Canadian-dollar_RMB.xlsx‘
forecastnum = 5
data = pd.read_excel(discfile, index_col = ‘时间‘)
data = data[‘收‘]
plt.rcParams[‘font.sans-serif‘] = [‘SimHei‘]
##datetime时间转化
data.index = pd.to_datetime(data.index,format="%Y/%m/%d")
plt.figure(figsize=(8,4))
plt.plot(data)
plt.show()
##ACF,PACF计算
fig = plt.figure(figsize = (12,8))

ax1 = fig.add_subplot(211)
fig = plot_acf(data,lags = 40,ax =ax1)
ax1.xaxis.set_ticks_position(‘bottom‘)
fig.tight_layout()

ax2 = fig.add_subplot(212)
fig = plot_pacf(data,lags = 40,ax =ax2)
ax1.xaxis.set_ticks_position(‘bottom‘)
fig.tight_layout()
data_diff = data.diff(5)
data_diff = data_diff.dropna()

##ACF,PACF计算
fig = plt.figure(figsize = (12,8))

ax1 = fig.add_subplot(211)
fig = plot_acf(data_diff,lags = 40,ax =ax1)
ax1.xaxis.set_ticks_position(‘bottom‘)
fig.tight_layout()

ax2 = fig.add_subplot(212)
fig = plot_pacf(data_diff,lags = 40,ax =ax2)
ax1.xaxis.set_ticks_position(‘bottom‘)
fig.tight_layout()

arima11 = sm.tsa.arima_model.ARMA(data_diff,order=(6,4))
model_results=arima11.fit()

predict = model_results.predict()
forecast = model_results.forecast(5)
plt.figure(figsize=(12,8))
plt.plot(data_diff.iloc[data_diff.size-1000:data_diff.size])
plt.plot(predict[data_diff.size-1000:data_diff.size],‘r‘)
plt.show()

forecast[1]

Canadian-dollar_RMB

标签:git   graphic   for   code   hung   port   nts   xls   plt   

原文地址:https://www.cnblogs.com/GitHung-Zeng/p/10201865.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!