MA_Strategy.py 文件源码

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

项目:rqalpha-mod-fxdayu-source 作者: xingetouzi 项目源码 文件源码
def handle_bar(context, bar_dict):
    prices = history_bars(context.s1, context.LONGPERIOD + 1, frequency, 'close')
    short_avg = talib.SMA(prices, context.SHORTPERIOD)
    long_avg = talib.SMA(prices, context.LONGPERIOD)

    # ????portfolio??????
    cur_position = context.portfolio.positions[context.s1].quantity
    avg_price = context.portfolio.positions[context.s1].avg_price
    capital = cur_position * avg_price
    # ????portfolio????????????
    shares = context.portfolio.cash / bar_dict[context.s1].close
    # ??????????
    plot('capital', capital)

    # ???????????????????bar?????????????
    if short_avg[-1] - long_avg[-1] < 0 < long_avg[-2] - short_avg[-2] and cur_position > 0:
        # ????
        order_target_value(context.s1, 0)

    # ????????????????????
    if short_avg[-1] - long_avg[-1] > 0 > long_avg[-2] - short_avg[-2]:
        # ????
        order_shares(context.s1, shares)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号