绘制MACD线,并且识别出金叉死叉位置

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

输出:

绘制MACD线,并且识别出金叉死叉位置_第1张图片
600066.png

Index([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')

你可能感兴趣的:(绘制MACD线,并且识别出金叉死叉位置)