7 用Ta-lib计算MACD

作者: readilen | 来源:发表于2017-05-25 07:36 被阅读526次

    熟悉了Ta-lib的api之后,我们来试试看用MACD指标。

    import pandas as pd
    import numpy as np
    import talib as ta
    import tushare as ts
    from matplotlib import rc
    rc('mathtext', default='regular')
    import seaborn as sns
    sns.set_style('white')
    %matplotlib inline
    
    dw = ts.get_k_data("600600")
    close = dw.close.values
    dw['macd'], dw['macdsignal'], dw['macdhist'] = talib.MACD(close, fastperiod=12, slowperiod=26, signalperiod=9)
    dw[['close','macd','macdsignal','macdhist']].plot()
    
    macd曲线

    上面的这个例子中,MACD 函数会运算3组值,其中:

    macd = 12 天 EMA - 26 天 EMA
    signal = 9 天 MACD的EMA
    hist = MACD - MACD signal

    相关文章

      网友评论

        本文标题:7 用Ta-lib计算MACD

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