7.2 Slippage
How it works
- Close - No slippage is applied 滑点不适用
This order is matched against the close price and this price is the last one of the day. Slippage cannot happen because the order can only happen with the last tick of the session and this is a unique price with no tolerance.
- Market - Slippage is applied 和下一个bar数据的open价格相匹配
Please check the slip_open exception. Because Market orders will be matched against the opening price of the next bar.如果slip_open设定为True, 则执行价格会在open上做调整
- Limit - Slippage is applied following this logic
If the matching price would be the opening price, then slippage is applied according to the parameter slip_open. If applied, the price will never be worse than the requested limit price 如果和open price价格相匹配,则以open价格执行
If the matching price is not the limit price, slippage is applied capping at high/low. In this case slip_limit applies to decide if a match will be happening in case the caps are exceeded 如果匹配价格不是limit price,slip_limit起作用了,执行价格为limit +/- limit_price, 并且在匹配过程中high/low price 也会根据滑点做调整
If the matching price is the limit price, then no slippage is applied。 如果匹配价格就是limit price, 则没有考虑滑点
Stop - once the order is triggered the same logic as for Market orders apply
当订单触发后,滑点的适用逻辑和Market 订单一致
StopLimit - once the order is triggered the same logic as for Limit orders apply
当订单触发后,滑点的适用逻辑和Limit 订单一致。
Configuring slippage
-
通过set_slippage_perc 和 set_slippage_fixed 两种方法设置
-
通过重新设置broker的slip参数
import backtrader as btcerebro = bt.Cerebro()
cerebro.broker = bt.brokers.BackBroker(slip_perc=0.005) # 0.5%