I have been using Quantconnect for about a year and am really pleased with its functionality. I am trying to calculate market buy volume minus market sell volume (i.e., cumulative delta – buy volume being considered buying at ask, and sell volume being considered selling at bid), and am wondering if this is currently possible using Quantconnect? This usage would be intraday for equities on a minimum of 1-second to 1-minute timeframe. I have looked through past posts and it seemed like some order book data is available, but I am not sure exactly if cumulative delta can be calculated using currently available data. I used to day trade manually and would use L2 data a little bit but do not really consider myself very well-versed with it, and especially within the context of data that is available in Quantconnect some guidance on whether calculating this indicator is feasible would be appreciated.
Sort of a separate topic, but currently I am just counting “buy” and “sell” volume whenever an OHLC candle is green or red and summing these values (similar to On-balance volume), which I imagine is better than nothing but definitely not the same thing, and probably not as effective, as tracking true market orders. Alternately I was thinking of taking this “buy” and “sell” volume, and multiplying it by the size of the candle, the implication being that market orders will move price more compared to limit orders, although this is still sort of a hacky solution compared to simply taking the actual volume of market orders. I would also be curious if anyone has ideas about the utility of these indicators, especially if cumulative delta cannot be calculated currently using Quantconnect.
Thanks.
Louis Szeto
Hi Dahui
It has to be done by tick resolution data and classify in every slice (tick) of tradebar data received. Please find the attached backtest as an example. It could cause problems like slowing down the backtest extensively and might not be translatable to live trade as the computation has to be simple enough to catch up with the trading speed.
Please note that there are 2 TickType in the example algorithm. TickType.Quote is only a quote but not the actual trade, so it has BidPrice and AskPrice but not Price attribute, while TickType.Trade is an actual trade with Price but no BidPrice and AskPrice.
Nevertheless, the differentiation of buy and sell volume as described could be hard to have a clear cut. For liquid securities, the bid-ask spread could be in 1-2 pip and kept swinging from allowing a clear cut, while illiquid ones both sides could be constantly bargaining.
Best
Louis Szeto
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Dahui
Hi Louis,
Thank you for providing this example code. However, when I run it, it seems to always return 0 for both QQQ and SPY's “buy” volume. I was wondering if you may know where the issue is? Sorry to not be proactive about solving it, but I was hoping to have some sort of gold-standard solution I could base further analyses off of, as I'm currently not very familiar with this type of data. Thanks.
Louis Szeto
Hi Dahui
It is because a Quote could only be either a buy or a sell, so it only contains either a BidPrice or an AskPrice while the other is 0. If the last quote is a sell before a trade, it will always be sellVolume. Please find the attached backtest as an amendment to the previous one to handle the issue.
Best
Louis
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Garrison Whipple
Louis Szeto the total volume for the day on an instrument like S&P 500 futures does not match what CME is reporting, even when extended hours are set to true. I get 1.5m buy and sell volume while CME shows 1.65m total volume on 8-17-22, what does that mean?
Louis Szeto
Hi Garrison
Could you please attach a backtest for further investigation? Thank you
Best
Louis
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Dahui
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 QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect 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. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!