Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
what am I missing in order timing? I feel like my order should be placed 1 minute sooner than it is.

My algo should be buying after a volume spike. The volume spike occurred for the trading minute starting at 10:45. My order doesn't trade until 10:47. Is this standard or am I doing something that is commonly wrong?

I'm just using:
order_target_percent(stock, context.long_pct_per_stock)

Thank you.

5 responses

I believe what's happening is this.

  1. volume spike occurs during trading minute 10:45
  2. any time you check volume or price you are looking at the PREVIOUS bar data. Therefore at 10:46 is when you would see the spike. I assume you enter an order then.
  3. the order is executed in the next bar or 10:47. The interesting point here is that while it's being reported as executed at 10:47 the backtest cost (say it was a market order) uses the close of the previous minute (ie 10:46 or the same minute the order was placed). Note however it may not go through in that minute if it's a thinly traded stock and there weren't any trades that minute.

The common thread is that the only data that Quantopian (live and backtest) has access to is minute data as of the close of the previous minute. This is primarily a function of the backtest being a discrete simulation with minute resolution. Live trading you would get the same price/volume updates at the end of each bar (you are using Quantopian data when trading live which updates exactly like the backtest). However, you may get your order executed within the same minute it was placed and at a different 'intra-bar' price and not the close price.

Thanks a lot for the response. Most of it makes sense to me.

to confirm #3 above, specifically your quote: "The interesting point here is that while it's being reported as executed at 10:47 the backtest cost (say it was a market order) uses the close of the previous minute (ie 10:46 or the same minute the order was placed). Note however it may not go through in that minute if it's a thinly traded stock and there weren't any trades that minute."

This was a small order for Facebook (FB), so if live trading and assuming a market order, the trade would most likely execute at 10:46:01, but back-testing will always show the closing price for the 10:46 minute in transaction details for all trades?

Again, thanks for the response, very helpful.

@michael

Correct. Quantopian doesn't know any finer resolution than minute bars. It uses the previous bar close price as the 'market' price for a security. BTW there's no telling if the price at 10:46:01 will be higher or lower than at the close of that minute.

Be careful in live trading. I am an advocate for always placing limit orders instead of market orders. You can set the limit to the current market and it will typically go through. In less volatile stocks (which are a lot that don't trade every minute) you may find some BIG surprises in live trading. If the last trade price for a stock was perhaps $10 and you placed a market buy order (expecting it to fill at $10) you would sure be surprised if you bought it at $15. This has happened to me more times than I care to admit. All someone needs to do is have a GTC sell limit order out there for $15. If at the instant you placed your order that limit sell order is the only one out there, guess what, you just bough it at that price.

Good luck.

Cool. Thx for confirming and the info on thinly traded companies. This is why my algo is the top 20 market cap companies in the sp500 - hopefully I'll never have to worry about that.

I got to thinking, which is usually dangerous for everyone around me... is there a way to change the order price from the closing price of the 10:46 bar, in my example above, to the opening price of the 10:46 minute?

It would be more like live trading, given my orders will be smaller and only using megacap stocks.