Python量化分析,计算KDJ (使用如下方法计算与国内财经软件显示一致)

def calKdj(df):
    low_list = df['low'].rolling(9, min_periods=9).min()
    low_list.fillna(value=df['low'].expanding().min(), inplace=True)
    high_list = df['high'].rolling(9, min_periods=9).max()
    high_list.fillna(value=df['high'].expanding().max(), inplace=True)
    rsv = (df['close'] - low_list) / (high_list - low_list) * 100
 
    df['K'] = pd.Series.ewm(rsv, com=2).mean()
    df['D'] = pd.Series.ewm(df['K'], com=2).mean()
    df['J'] = 3 * df['K'] - 2 * df['D']

    return df

 

posted @ 2022-02-03 20:58  锐洋智能  阅读(457)  评论(0编辑  收藏  举报