How do you compensate for bid/ask when designing algos?

I have designed an algo around the 1 minute vwap - I think the profit I’m looking at in tests will be eaten up by the bid/ask spread. Polygon offers historical quotes, and I was thinking of incorporating this into the algo. What is the best way to deal with this? Taking the high and low of the minute bar as the respective ask/bid to be conservative?

1 Like

You would really need to get historical BBO (best bid/offer) data to get a more precise view on realized price you can achieve (or better yet consolidated book data). You also need to assume that your order will hit the market with latency and may not be the first in line to grab the available inside price. So in addition to crossing the spread you need to make some assumptions about missing the offer (bid) when buying (selling) if you are crossing the spread to get a fill.

If you are using minute bars in backtesting, one characteristic of these bars is that they are built off of actual trades in the market. While we know where the high and the low of the bar were, we will not have any idea where the price was at any given instant during the bar. The best you can do is have an idea if an order placed before the bar would be filled. If the next bar’s low -> high range is within your pre-bar order’s price range then you have a good chance that it would have been filled. However there are all sorts of other factors around: the size of the order, market impact, your position in the queue.

Oh, and because retail brokers send their flow to market makers rather than routing to the exchange, there are more variables in the equation in terms of where your fill will be …


Sounds like you’re cutting it too close.

I am! I’m changing the algo now…