I am trying to detect a gap up/down on open within my universe selection. Specifically, I want to identify tickers that have value at today's open greater than yesterday's close.
I currently have an active universe passed through a coarse filter and a fine filter. Within the fine filter i want to further filter the results by checking if the stock has gapped up overnight. I can call the history of the stock inside the fine filter function without an issue. However i am struggling with getting the current data of the stock. My first instinct is to call for data[symbol].Open in ondata, however it returns no results. I think perhaps this is because that we did not addequity in the initialize step. However we cannot add equity if we do not know what stock to pass. How can I achieve my end goal of identifying stocks that have gapped in my universe selection?
Mia Alissi
Based on the information provided in the extracts, it seems that the Coarse Universe data set only provides the daily closing price. Therefore, it might not be possible to detect gap up/down on open directly within the universe selection as it requires both open and close prices.
However, you can still filter your universe based on other criteria and then, in the
OnData
method, use theHistory
method to get the historical data for the selected symbols. This will allow you to compare the current open price with the previous close price to detect a gap.Here is a simplified example of how you might do this:
In this example,
self.symbols
is a list of symbols that you have selected in your universe selection. Please note that this is a simplified example and you might need to adjust it according to your specific needs.Remember that calling the
History
method frequently might have a performance impact on your algorithm, so you should use it judiciously.For more information on how to use the
History
method, you can refer to the QuantConnect Documentation.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.
Ming Xu
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!