顺势指标(CCI)
CCI = talib.CCI(high, low, close, timeperiod=14)
资金流量指标(MFI)
MFI = talib.MFI(high, low, close, volume, timeperiod=14)
动力指标(MTM)
n 一般取12
def MTM(close, n):
mtm = []
for i in range(len(close)):
if i < n:
mtm.append(0)
else:
mtm.append(close[i] - close[i-n])
return mtm
m一般取6
def MTMMA(mtm, m):
return talib.SMA(mtm,m)
变动速率线
N一般取20
def OSC(close,n):
ma = talib.MA(close,n)
return [100 * (close[i] - ma[i]) for i in range(len(close))]
M一般取6
def OSCMA(OSC,m):
return talib.SMA(OSC,m)
变动率指标
ROC = talib.ROC(close, timeperiod=10)
def ROCMA(roc,m):
return talib.SMA(roc,m)
相对强弱指标RSI
RS = sum(n期内上涨幅度)/sum(n期内下跌幅度)
RSI = 100 - 100/(1 + RS) = 100RS/(1 + RS)
def RS(close,n):
value_list= []
lenght = len(close)
for i in range(lenght):
if i==0:
value_list.append(0)
else:
value_list.append(close[i]-close[i-1])
rs_list = []
for v_id in range(lenght):
if v_id<n:
rs_list.append(0)
else:
p_sum = 0
p_count = 0
n_sum = 0
n_count = 0
for j in range(v_id-n,v_id):
if value_list[j]>0:
p_sum += value_list[j]
p_count +=1
else:
n_sum += value_list[j]* (-1)
n_count += 1
if p_count == 0:
rs_list.append(0)
if n_count == 0:
rs_list.append(0)
if p_count != 0 and n_count != 0:
rs_list.append(round((p_sum)/(n_sum),6))
return rs_list
def RSI(rs_list):
return [100 - 100/(1+rs) for rs in rs_list]
RSI = talib.RSI(close, timeperiod=14)
随机指标KD
RSV = 100 * (close - min(最近n日内low)/ ( max(最近n日内high)-min(最近n日内low))
K线:RSV的M1日移动平均线
D线:K值的M2日移动平均线
参数一般取值:n=9,m1=3,m2=3
talib.STOCH(high, low, close, fastk_period=9, slowk_period=3, slowk_matype=0, slowd_period=3, slowd_matype=0)
随机指标KDJ
RSV = 100 * (close - min(最近n日内low)/ ( max(最近n日内high)-min(最近n日内low))
K线:RSV的M1日移动平均线
D线:K值的M2日移动平均线
J线:3k - 2d
参数一般取值:n=9,m1=3,m2=3
def KDJ(high, low, close, fastk_period=9, slowk_period=3, slowk_matype=0, slowd_period=3, slowd_matype=0):
k,d = talib.STOCH(high, low, close, fastk_period, slowk_period, slowk_matype, slowd_period, slowd_matype)
j = []
for i in range(len(k)):
j.append(3*k[i] - 2*d[i])
return k,d,j
威廉指标W%R
WR1 = 100*(N日内max(high) - 当前close)/(N日内max(high) - N日内min(low))¶
N 一般取6或者10
talib.WILLR(high, low, close, timeperiod = 6)
乖离率(BIAS)
def BIAS(close,n):
ma = talib.MA(close,n)
bias = []
for i in range(len(close)):
bias.append(100 * (close[i] - ma[i])/ma[i])
return bias
唐奇安通道(DC)
up = 过去20日内的最高价
down = 过去20日内的最低价
mid = (up + down)/2
def DC(close,n):
up = []
down = []
mid = []
for i in range(len(close)):
if i<n:
up.append(max(close[:i]))
down.append(min(close[:i]))
mid.append(0.5*(up[i]+down[i]))
else:
up.append(max(close[i-n:i]))
down.append(min(close[i-n:i]))
mid.append(0.5*(up[i]+down[i]))
return down,mid,up
布林极限(BB)
布林极限 = (c - down)/ (up - down)
def BB(close,n,bias_n):
up,mid,low = talib.BBANDS(df.close_price,5,matype = talib.MA_Type.SMA)
bb = []
for i in range(len(close)):
bb.append((close[i]-down[i])/(up[i] - down[i]))
return bb
真实波幅通道 ATR_CHANNEL
TR = MAX(high - low, abs(pre_close - high), abs(pre_close - low))¶
ATR =SMA(TR)
up = open + ATR * M
down = open - ATR * M
def ATR_CHANNEL(open_price,atr,m=1):
up = []
down = []
for i in range(len(open_price)):
up.append(open_price[i] + m * atr[i])
down.append(open_price[i] - m * atr[i])
return up,down
二、能量型指标
人气指标AR
def AR(o,h,l,n):
h_o = h - o
o_l = o - l
ar = []
for i in range(len(o)):
if i<n:
ar.append(1)
else:
ar.append(100 * sum(h_o[i-n:i])/sum(o_l[i-n:i]))
return ar
心理线PSY
# PSY = 100 * SUM(UP)/N
def PSY(open_price, close_price,n):
is_up = (close_price > open_price).astype('int')
psy = []
for i in range(len(open_price)):
if i<n:
psy.append(0)
else:
psy.append(100 * sum(is_up[i-n:i])/n)
return psy
成交变异率VR
def VR(o,c,v,n):
vr = []
for i in range(len(o)):
if i<n-1:
vr.append(0)
else:
sv = 0
wv = 0
for j in range(n):
if o[i+1-n+j]<c[i+1-n+j]:
sv += v[i+1-n+j]
elif o[i-n+j]>c[i+1-n+j]:
wv += v[i-n+j]
else:
sv += v[i+1-n+j]*0.5
wv+= v[i+1-n+j]*0.5
if wv == 0:
vr.append(1000)
else:
vr.append(100 * sv/wv)
return vr
VR(open,close,volume,5)
威廉多空力度线(WAD)
结合价格来进行使用
def WAD(close,high,low):
wad = []
for i in range(len(close)):
if i==0:
wad.append(0)
continue
trl = min(close[i-1],low[i])
trh = max(close[i-1],high)
if close[i-1]<close[i]:
ad = close[i] - trl
elif close[i-1]> close[i]:
ad = close[i] - trh
else:
ad = 0
if i == 1:
wad.append(ad)
else:
wad.append(wad[-1] + ad)
return wad
# 幅度比(PCNT)
def PCNT(close):
pcnt = []
for i in range(len(close)):
if i==0:
pcnt.append(0)
else:
pcnt.append(100*(close[i]-close[i-1])/close[i])
return pcnt
三、趋势型技术指标
平均差(DMA)
dif向上交ama
dif向下交ama
def DMA(close,n_1,n_2,m):
dif = talib.MA(close,n_1) - talib.MA(close,n_2)
ama = talib.MA(dif,m)
return dif,ama
简易波动指标(EMV)
def EMV(high,low,volume,n):
em = []
for i in range(len(low)):
if i == 0:
em.append(0)
else:
a = (high[i] + low[i])/2
b = (high[i-1] + low[i-1])/2
c = high[i] - low[i]
em.append((a-b)*c/volume[i])
emv = []
for i in range(len(low)):
if i<n:
emv.append(sum(em[:i]))
else:
emv.append(sum(em[i-n:i]))
return emv
def EMVMA(emv,m):
return talib.SMA(emv,m)
平滑异同平均(MACD)
dif = ema(close,short) - ema(close,long)
dea = ema(dif,mid)
macd = dif - dea
macd, dif, dea = talib.MACD(df.close_price, fastperiod=12, slowperiod=26, signalperiod=9)
三重平滑指标(TRIX)
TR = close的N日异同移动平均的N日异同移动平均的N日异同移动平均(三重)
TRIX = 100 * (TR - pre_TR)/pre_TR
TMA = MA(TRIX)
trix = talib.TRIX(df.close_price, timeperiod=12)
def TMA(trix,m):
return talib.SMA(trix,m)
威廉变异离散量(WVAD)
A = C-O
B = H - L
C = (A/B)*V
WVAD = SUM(C,N)
def WVAD(o,h,l,c,v,n):
wvad = []
c_list = []
for i in range(len(o)):
a = c[i] - o[i]
b = h[i] - l[i]
c_list.append(a/b*v[i])
if i < n:
wvad.append(sum(c_list[:-1]))
else:
wvad.append(sum(c_list[i-n:i]))
return wvad
加速线(JS)
def JS(close,n):
js = []
for i in range(len(close)):
if i<n:
if i==0:
js.append(0)
else:
js.append(100 * (close[i]-close[0])/((i-0)*close[0]))
else:
js.append(100 * (close[i]-close[i-n])/(n*close[i-n]))
return js
def JSMA(js,m):
return talib.MA(js,m)