Hi everyone!
I have subscribed to 2 stocks at different resolutions, SPY at minute resolution and AAPL at hour resolution.
I was under the assumption that since I have subscribed to minute and hour bars for my algorithm, that OnData will receive minute and hour bars separately, (i.e. OnData will receive SPY's data every minute and only receive AAPL's data every hour).
What I'm getting is, OnData is getting triggered every minute and receiving SPY's minute data (as it should) but it's also spitting out AAPL's past hour data every minute.
To further clarify what I'm trying to explain, attached is a backtest that prints close price data for each stock in the algorithm, Before 10 am, the algorithm is only printing data for SPY every minute. After 10 am, it's printing data for both SPY and AAPL every minute (even though it is not receiving any new data for AAPL and the algorithm uses .containskey to check if data contains AAPL).
How do I check if a new hour bar is received for AAPL without changing AAPL's resolution to minute using a consolidator to consolidate hour bars?
Varad Kabade
Hi Li Cheng,
This happens because the data has FillForward set to true by default i.e if the current slice object does not have data for a subscribed security it gets filled by the last value. To resolve this, we recommend adding the security as follows:
Best,
Varad Kabade
Li Cheng
Hi Varad, thanks for the reply, and the information!
I should've known to try changing Data Fillforward to False to solve this issue!
Greatly appreciate your help!
Li Cheng
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!