Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Newbie Question of Quote Lag and Execution Lag

Hello all, my question is about the time lag of quote and execution in live trading. Quantopian calls handle_data every minute. When handle_data is called, does data[sid].price quote the contemporary price? Or a price, say, 1 minute lagged? Also, is it safe to say the time for quantopian to run handle_data and send execution order to IB is negligible compared to 1 minute? Thanks a lot!

6 responses

Hello Han,

The basic outline is that Quantopian uses a live data feed called Nanex Nxcore (see https://www.quantopian.com/faq#data). On-the-fly, they compute OHLCV minutely bars as the data come in. So, when handle_data is called, your algorithm has access to the latest minutely bar, and the closing price (same as data[sid].price) falls somewhere in time within that trailing minute. There are no timestamps on the individual OHLC values, so there is no way to know how much time has elapsed between the OHLC market trade events and the call to handle_data.

Regarding "the time for Quantopian to run handle_data and send execution order to IB," Jonathan Kamens recently provided some data, and the timing is on the order of a second or more (see https://www.quantopian.com/posts/skip-avoid-bypass-ignore-handle-data-using-schedule-function-only). As he points out, if there is significant data processing by the algorithm during the handle_data call, then the delay will be longer (it could be up to 50 seconds, beyond which the algo will timeout and crash).

I would caution you in assuming tight timing, since it is not clear how much overall latency and timing jitter (and glitching) there is between the market events that drive the Nanex Nxcore data feed and the execution of orders at Interactive Brokers. I'd consider it to be a minute-level-timing, pseudo-real-time system at this point, until more information is provided.

Grant

I see. Thanks Grant!

Jonathan Kamens recently provided some data, and the timing is on the order of a second or more

That is not what I said.

I said that the average time to the end of handle_data was 1.06 seconds, and that 69% of calls to handle_data finish in less than 1 second.

In other words, if your handle_data doesn't do compute-intensive work, then most of the time it will complete within a fraction of a second after the end of the minute.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

OK. Thanks!~

Hi Jonathan,

Sorry for the mis-quote, and thanks for your correction. In light of my other comments, though, the exact delay between the call to handle_data and the subsequent transmission of data to Interactive Brokers wouldn't seem all that relevant, since other delays have not been taken into account. Anyway, the system works, and people are reportedly making money with it. So, full steam ahead!

Grant

To address the execution question, trades are transmitted to IB immediately when the order method is called in the user's algorithm. We're not talking about microseconds -- as has been pointed out repeatedly, Quantopian is not, nor is it intended to be, an HFT platform -- but in the normal case, an order will make it to IB in less than 0.2 seconds after it is placed by the algorithm.