How to handle a wide bid-ask spread?
Wendroff last edited by
I'm a beginner of backtrader. I read all the document and found that the excute price only depend on the OHLC (open-high-low-close) price. What if the underlying asset has a wide bid-ask spread? Can backtrader handle this kind thing?
backtrader was never meant for
bid-asksimulation and it for a very simple reason.
Let's imagine you have an
OHLCand you have a limit order with a price that happens to sit in the middle of the
limit price = (H + L) / 2)
If the timeframe of the bar is
1-dayand we look at recent
ES-Minibars the range can be
2771with our limit price right at
We don't really know when the
2831price was hit during the day. The question here: Which bid-ask prices have to be considered for matching the desired limit price?.
When we see the bar the only valid
bid-askprices would be that corresponding to the
closewhich in this case was
2772, far far away from our price. And even if we had information for the
bid-askprices for the area
2831, this price could have been crossed several times during the day, so at which time do we execute the trade?
Because backtrader has to work with any timeframe, the
bid-askcomponent as shown cannot be really considered.
That's why people use slippage: Docs - Slippage which simply worsens your matching price.
In any case and for a
Limitorder, one shouldn't apply slippage because the
Limitorder will be matched at the requested or at a better price. Use it for