data_handler.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:pyktrader2 作者: harveywwu 项目源码 文件源码
def ASCTREND(df, n, risk = 3, stop_ratio = 0.5, atr_mode = 0):
    wpr = WPR(df, n)
    uplevel = 67 + risk
    dnlevel = 33 - risk
    signal = pd.Series(0, index = df.index, name = "ASCSIG_%s" % str(n))
    trend = pd.Series(index = df.index, name = "ASCTRD_%s" % str(n))
    stop = pd.Series(index = df.index, name = "ASCSTOP_%s" % str(n))
    ind = (wpr >= uplevel) & (wpr.shift(1) < uplevel)
    signal[ind] = 1
    trend[ind] = 1
    ind = (wpr <= dnlevel) & (wpr.shift(1) > dnlevel)
    signal[ind] = -1
    trend[ind] = -1
    trend = trend.fillna(method='ffill')
    if atr_mode == 0:
        atr = ATR(df, n + 1)
    else:
        atr = pd.rolling_mean(df['high'] - df['low'], n + 1)
    stop[trend > 0] = df['low'] - stop_ratio * atr
    stop[trend < 0] = df['high'] + stop_ratio * atr
    return pd.concat([signal, trend, stop], join='outer', axis=1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号