import pandas as pdimport matplotlib.pyplot as pltimport statsmodels as smfrom statsmodels.graphics.tsaplots import plot_acf,plot_pacfimport numpy as npdiscfile = r'D:\python\日线数据\renminbi_ouyuan.xlsx'forecastnum = 5data = pd.read_excel(discfile, index_col = '时间')data = data['收']dataplt.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()