Python: v3.6
Pandas: v0.23.4
使用以下方法计算与国内财经软件显示一致
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']
注意:
1、别使用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_金叉死叉'] = '死叉'