How to handle a wide bid-ask spread?
-
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-ask
simulation and it for a very simple reason.Let's imagine you have an
OHLC
and you have a limit order with a price that happens to sit in the middle of theHL
range (i.e.:limit price = (H + L) / 2
)If the timeframe of the bar is
1-day
and we look at recentES-Mini
bars the range can be120 points
between2891
and2771
with our limit price right at2831
.We don't really know when the
2831
price 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-ask
prices would be that corresponding to theclose
which in this case was2772
, far far away from our price. And even if we had information for thebid-ask
prices for the area2831
, 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-ask
component 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
Limit
order, one shouldn't apply slippage because theLimit
order will be matched at the requested or at a better price. Use it forMarket
orders.