Python计算kdj

Ft 2020-10-18 PM 57℃ 0条
low_list = df['最低价'].rolling(9, min_periods=9).min()
low_list.fillna(value = df['最低价'].expanding().min(), inplace = True)
high_list = df['最高价'].rolling(9, min_periods=9).max()
high_list.fillna(value = df['最高价'].expanding().max(), inplace = True)
rsv = (df['收盘价'] - low_list) / (high_list - low_list) * 100

df['K'] = pd.DataFrame(rsv).ewm(com=2).mean()
df['D'] = df['K'].ewm(com=2).mean()
df['J'] = 3 * df['K'] - 2 * df['D']

注意:别使用TA-Lib进行计算(如使用talib.STOCH()方法),计算结果与国内的财经软件不一致

附:KDJ金叉死叉计算方法
df['KDJ_金叉死叉'] = ''
kdj_position=df['K']>df['D']
df.loc[kdj_position[(kdj_position == True) & (kdj_position.shift() == False)].index, 'KDJ_金叉死叉'] = '金叉'
df.loc[kdj_position[(kdj_position == False) & (kdj_position.shift() == True)].index, 'KDJ_金叉死叉'] = '死叉'
标签: python

非特殊说明,本博所有文章均为博主原创。

评论啦~