ricequant / rqalpha

A extendable, replaceable Python algorithmic backtest && trading framework supporting multiple securities
http://rqalpha.io
Other
5.38k stars 1.61k forks source link

Matcher并没有真正地考虑算法单特定目标的执行情况? #833

Closed walkacross closed 7 months ago

walkacross commented 10 months ago

文档中写到,rqalpha提供了TWAPOrder(931, 945),允许

order_shares("000001.XSHE", amount=1000, price_or_style=TWAPOrder(931, 945))

虽然开源版本不支持get_algo_bar(self, id_or_ins, start_min, end_min, dt), 但在Matcher的实际撮合逻辑中,并没有考虑算法单的情况

        if self._volume_limit:
            volume = self._get_bar_volume(order, open_auction=open_auction)
            if volume == volume:
                volume_limit = round(volume * self._volume_percent) - self._turnover[order.order_book_id]

                round_lot = instrument.round_lot
                volume_limit = (volume_limit // round_lot) * round_lot
                if volume_limit <= 0:
                    if order.type == ORDER_TYPE.MARKET:
                        reason = _(u"Order Cancelled: market order {order_book_id} volume {order_volume}"
                                   u" due to volume limit").format(
                            order_book_id=order.order_book_id,
                            order_volume=order.quantity
                        )
                        order.mark_cancelled(reason)
                    return

                fill = min(order.unfilled_quantity, volume_limit)
            else:
                fill = order.unfilled_quantity
        else:
            fill = order.unfilled_quantity

如果是分钟频率的回测,如果volume_limit > 1000, 即便该订单是TWAPOrder, fill也会直接是1000, 并没有真正的考虑随着时间均匀下单的目标?

Cuizi7 commented 7 months ago

是的,这个功能并不是在回测中真实地执行一个算法单,只是让订单以理想状态下算法单的价格成交。它的应用场景并不是对算法交易进行回测,而是希望在中低频的回测中剥离执行层面的影响。