美文网首页
绘制MACD线,并且识别出金叉死叉位置

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

作者: 那未必 | 来源:发表于2017-10-04 12:59 被阅读38次
    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.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线,并且识别出金叉死叉位置

          本文链接:https://www.haomeiwen.com/subject/sxtcyxtx.html