def drawBBANDS(ax, data, period=20): if data.__contains__('upper_band') & data.__contains__( 'middle_band') & data.__contains__('lower_band'): upper_band = data['upper_band'] middle_band = data['middle_band'] lower_band = data['lower_band'] else: close = data['close'] upper_band, middle_band, lower_band = ind.BBANDS(close, time_period=period) ax.plot(upper_band, label='upper_band') ax.plot(middle_band, label='middle_band') ax.plot(lower_band, label='lower_band')
# AMZN # GOOG # .HK .SZ .HZ # 300059.sz # pdi 10~20 13~16 # mdi data = web.DataReader('300059.sz', data_source='yahoo', start='1/1/2018', end='1/30/2019') data = pd.DataFrame(data) high, low, close, volume = data['High'], data['Low'], data['Close'], data[ 'Volume'] pdi, mdi = ind.DI(high, low, close, time_period=14) adx = ind.ADX(high, low, close, time_period=6) upper_band, middle_band, lower_band = ind.BBANDS(close, time_period=20) m, s, macd_histogram = ind.MACD(close, fast_period=12, slow_period=26, signal_period=9) rsi = ind.RSI(close, time_period=14) min = ind.MIN(close, 20) max = ind.MAX(close, 50) df = pd.DataFrame() df['close'] = close df['fast'] = m df['slow'] = s df['ref'] = df['fast'].shift(1) < df['slow'].shift(1) df['now'] = df['fast'] > df['slow'] df['cross'] = (m.shift(1) < s.shift(1)) & (m > s)