代码如下:
data=pd.read_excel(r'C:\Users\Administrator\Desktop\恒生指数\HSI.xlsx',sheetname='HSI')
data['std']=pd.rolling_std(data['close'],20)
data['boll']=pd.rolling_mean(data['close'],20)
data['upper']=data['boll']+2*data['std']
data['lower']=data['boll']-2*data['std']
data=data.dropna()
data=data[:300]
#画图
plt.plot(data['boll'])
plt.plot(data['upper'])
plt.plot(data['lower'])
plt.show()
图二是excel做的