Stochastic Oscillator Slow (Stoch)更直接的理解就是我們常用的KDJ指標中的KD指標孩灯。是由兩條線一條是快速確認線,另外一條是慢速主干線組成逾滥》宓担可以參考鏈接*Talib推薦STOCH參考*****計算方法:隨機線有四種败匹,分別是: FASTK, FASTD, SLOWK and SLOWD,D是由K經(jīng)過變化得到讥巡。具體計算如下圖掀亩。
import pandas as pd
import numpy as np
import talib as ta
import tushare as ts
import matplotlib.pyplot as plt
from matplotlib import rc
rc('mathtext', default='regular')
import seaborn as sns
sns.set_style('white')
from matplotlib import dates
import matplotlib as mpl
%matplotlib inline
myfont =mpl.font_manager.FontProperties(fname=r"c:\windows\fonts\simsun.ttc",size=14)
plt.rcParams["figure.figsize"] = (20,10)
dw = ts.get_k_data("600600")
dw = dw[300:]
dw.index = range(len(dw))
dw['slowk'], dw['slowd'] = ta.STOCH(dw['high'].values,
dw['low'].values,
dw['close'].values,
fastk_period=9,
slowk_period=3,
slowk_matype=0,
slowd_period=3,
slowd_matype=0)
fig = plt.figure(figsize=(20,10))
fig.set_tight_layout(True)
ax1 = fig.add_subplot(111)
#fig.bar(dw.index, dw.volume, align='center', width=1.0)
ax1.plot(dw.index, dw.close, '-', color='g')
ax2 =ax1.twinx()
ax2.plot(dw.index, dw.slowk, '-', color='r')
ax2.plot(dw.index, dw.slowd, '-', color='b')
ax2.plot(dw.index, [90]*len(dw), '-', color='m')
ax2.plot(dw.index, [10]*len(dw), '-', color='m')
ax1.set_ylabel(u"股票價格(綠色)",fontproperties=myfont, fontsize=16)
ax2.set_ylabel(u"STOCH",fontproperties=myfont, fontsize=16)
ax1.set_title(u"綠色是股票價格,紅色(右軸)STOCH",fontproperties=myfont, fontsize=16)
# plt.xticks(bar_data.index.values, bar_data.barNo.values)
ax1.set_xlabel(u"STOCH",fontproperties=myfont,fontsize=16)
ax1.set_xlim(left=-1,right=len(dw))
ax1.grid()
plt.legend(loc='upper left')