Backtrader中文笔记之Slippage(滑点)
backtesting cannot guarantee real market conditions. No matter how good the market simulation is, under real market conditions slippage can happen. That means:
回测系统不能保证真实的市场状况。无论市场模拟有多好,在真实的市场条件下,都可能出现下滑。这意味着:
- The requested price may not be matched.
- 请求的价格可能不匹配
The integrated backtesting broker supports slippage. The following parameters can be passed to the broker
完整的回测券商【经纪人】支持滑点。可以将以下参数传递给券商【经纪人】
-
slip_perc(default:0.0) Percentage in absolute termns (and positive) that should be used to slip prices up/down for buy/sell orders - slip_perc(默认值:0.0)绝对条件下的百分比(和正值,用于向上/向下滑动买入/卖出订单的价格
-
Note:
-
0.01is1% -
0.001is0.1%
-
-
slip_fixed(default:0.0) Percentage in units (and positive) that should be used to slip prices up/down for buy/sell ordersNote: if
slip_percis non zero, it takes precendence over this. -
slip_open(default:False) whether to slip prices for order execution which would specifically used the opening price of the next bar. An example would beMarketorder which is executed with the next available tick, i.e: the opening price of the bar.This also applies to some of the other executions, because the logic tries to detect if the opening price would match the requested price/execution type when moving to a new bar.
-
slip_match(default:True)If
Truethe broker will offer a match by capping slippage athigh/lowprices in case they would be exceeded.If
Falsethe broker will not match the order with the current prices and will try execution during the next iteration -
slip_limit(default:True)Limitorders, given the exact match price requested, will be matched even ifslip_matchisFalse.This option controls that behavior.
If
True, thenLimitorders will be matched by capping prices to thelimit/high/lowpricesIf
Falseand slippage exceeds the cap, then there will be no match -
slip_out(default:False)Provide slippage even if the price falls outside the
high-lowrange.
How it works
如何工作
In order to decide when to apply slippage the order execution type is taken into account:
-
Close- No slippage is applied - 收盘-不支持引用滑点
-
This order is matched against the
closeprice 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 appliedPlease check the
slip_openexception. BecauseMarketorders will be matched against the opening price of the next bar. -
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 requestedlimitprice -
If the matching price is not the
limitprice, slippage is applied capping athigh/low. In this caseslip_mlimitapplies to decide if a match will be happening in case the caps are exceeded -
If the matching price is the
limitprice, then no slippage is applied
-
-
Stop- once the order is triggered the same logic as forMarketorders apply -
StopLimit- once the order is triggered the same logic as forLimitorders apply
This approach tries to offer the most realistic possible approach within the limits of the simulation and available data
浙公网安备 33010602011771号