import pandas as pd
from matplotlib import pyplot as plt
df_all=pd.read_csv('sh600066.csv',usecols=[1,5],index_col='date')
df_all=df_all.iloc[::-1]
df_all['ma5']=df_all['close'].rolling(5).mean()
df_all['ma10']=df_all['close'].rolling(10).mean()
df_range=df_all[10:80]
# 设定绘图大小
dpi = 72.
xinch = 800 / dpi
yinch = 400 / dpi
df_range[['ma5','ma10']].plot(figsize=(xinch,yinch))
plt.show()
goden_cross=df_range[(df_range['ma5']<=df_range['ma10']) & (df_range['ma5']>df_range['ma10']).shift(1)].index
print goden_cross
death_cross=df_range[(df_range['ma10']<=df_range['ma5']) & (df_range['ma10']>df_range['ma5']).shift(1)].index
print death_cross
输出:
600066.pngIndex([u'2013-02-22', u'2013-04-08', u'2013-05-02'], dtype='object', name=u'date')
Index([u'2013-03-20', u'2013-04-17', u'2013-05-07'], dtype='object', name=u'date')
网友评论