熟悉了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 函数会运算3组值,其中:
macd = 12 天 EMA - 26 天 EMA
signal = 9 天 MACD的EMA
hist = MACD - MACD signal