vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 10
声望: 0

当价格变化太快时,一根k线的价格变化分别满足两个不同价格的平仓条件时
,回测引擎是不是把其中一个平当成了开, 日志显示一个开仓,平仓有两个
def on_15min_bar(self, bar: BarData):
""""""
self.cancel_all()

    am = self.am
    am.update_bar(bar)
    if not am.inited:
        return

    self.boll_up, self.boll_down = am.boll(self.boll_window, self.boll_dev)
    self.boll_mid = am.sma(self.boll_window)
    self.atr_value = am.atr(self.atr_window)

    if self.pos == 0:
        self.buy(self.boll_up, self.fixed_size, True)
        self.short(self.boll_down, self.fixed_size, True)

        self.intra_trade_high = bar.high_price
        self.intra_trade_low = bar.low_price



    elif self.pos > 0:
        if bar.close_price <= self.boll_mid:
            self.sell(bar.close_price - 5, abs(self.pos))

        self.intra_trade_high = max(self.intra_trade_high, bar.high_price)
        self.intra_trade_low = bar.low_price

        self.long_sl = self.intra_trade_high - self.atr_value * self.atr_multiplier
        self.sell(self.long_sl, abs(self.pos), True)

    elif self.pos < 0:
        if bar.close_price >= self.boll_mid:
            self.cover(bar.close_price + 5, abs(self.pos))

        self.intra_trade_low = min(self.intra_trade_low, bar.low_price)
        self.intra_trade_high = bar.high_price

        self.short_sl = self.intra_trade_low + self.atr_value * self.atr_multiplier
        self.cover(self.short_sl, abs(self.pos), True)

    self.put_event()

回测日志:
trade: Direction.SHORT Offset.OPEN 1 BACKTESTING.1
trade: Direction.LONG Offset.CLOSE 2 BACKTESTING.2
trade: Direction.LONG Offset.CLOSE 3 BACKTESTING.3
trade: Direction.SHORT Offset.CLOSE 4 BACKTESTING.4
trade: Direction.LONG Offset.OPEN 5 BACKTESTING.5
trade: Direction.SHORT Offset.CLOSE 6 BACKTESTING.6
trade: Direction.LONG Offset.OPEN 7 BACKTESTING.7

Administrator
avatar
加入于:
帖子: 3566
声望: 189

回测引擎对开平委托,只是区别记录,并不像实盘环境中如果当前没有仓位直接平仓会报错拒单,但是这个并不会影响最终的盈亏统计

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3