def KDJ(security_list, fastk_period=5, slowk_period=3, fastd_period=3):
def SMA_CN(close, timeperiod):
close = np.nan_to_num(close)
return reduce(lambda x, y: ((timeperiod - 1) * x + y) / timeperiod, close)
# ????????????
if isinstance(security_list, str):
security_list = [security_list]
# ?? KDJ
n = max(fastk_period, slowk_period, fastd_period)
k = {}
d = {}
j = {}
for stock in security_list:
security_data = attribute_history(
stock, n * 2, '1d', fields=['high', 'low', 'close'], df=False)
high = security_data['high']
low = security_data['low']
close = security_data['close']
kValue, dValue = talib.STOCHF(
high, low, close, fastk_period, fastd_period, fastd_matype=0)
kValue = np.array(map(lambda x: SMA_CN(
kValue[:x], slowk_period), range(1, len(kValue) + 1)))
dValue = np.array(map(lambda x: SMA_CN(
kValue[:x], fastd_period), range(1, len(kValue) + 1)))
jValue = 3 * kValue - 2 * dValue
def func(arr): return np.array(
[0 if x < 0 else (100 if x > 100 else x) for x in arr])
k[stock] = func(kValue)
d[stock] = func(dValue)
j[stock] = func(jValue)
return k, d, j
# RSI
评论列表
文章目录