rsi.py 文件源码

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

项目:InplusTrader_Linux 作者: zhengwsh 项目源码 文件源码
def handle_bar(context, bar_dict):
    # ?????????????

    # bar_dict[order_book_id] ?????????bar??
    # context.portfolio ???????????????

    # ??order_shares(id_or_ins, amount)??????

    # TODO: ??????????

    # ????????????loop?????????RSI??
    for stock in context.stocks:
        # ??????
        prices = history_bars(stock, context.TIME_PERIOD+1, '1d', 'close')

        # ?Talib??RSI?
        rsi_data = talib.RSI(prices, timeperiod=context.TIME_PERIOD)[-1]

        cur_position = context.portfolio.positions[stock].quantity
        # ??????30%???????
        target_available_cash = context.portfolio.cash * context.ORDER_PERCENT

        # ?RSI???????????????
        if rsi_data > context.HIGH_RSI and cur_position > 0:
            order_target_value(stock, 0)

        # ?RSI?????????????cash?????????
        if rsi_data < context.LOW_RSI:
            logger.info("target available cash caled: " + str(target_available_cash))
            # ??????????? - 100shares?????ricequant ?order management system reject?
            order_value(stock, target_available_cash)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号