I want to filter out to build the stocks list which are within 5% of 52 weeks high before market open every day. How to add scan the stocks within 5% of 52 weeks every day
self.add_universe_selection(ETFConstituentsUniverseSelectionModel("SPY", self.universe_settings, self.etf_constituents_filter))
def etf_constituents_filter(self, constituents):
# Define your filtering logic here
return [c.symbol for c in constituents]
Mia Alissi
Here's the corrected implementation for filtering stocks within 5% of their 52-week high using the
ETFConstituentsUniverseSelectionModel
:Key Changes:
resolution
instead ofasynchronous
as it is read-only.before_market_open
tobefore_market_close
sincebefore_market_open
is not available.history
method is used correctly with the appropriate parameters.Sources: ETF Constituents Universes - QuantConnect.com, E T F Constituents Framework Algorithm, ETF Constituents Universes - QuantConnect.com, US ETF Constituents - QuantConnect.com, E T F Constituent Universe R S I Alpha Model Algorithm
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.
Dharmesh Khalasi
What is the rebalance implementation ? why we need ? how to implement add equity which are in the selected_symbol and how to implement on_data to iterate through only selected_symbols only ?
Louis Szeto
Hi Dharmesh
You don't necessarily need the rebalance scheduled event. Instead using on_data is perfectly fine. You don't need the add_equity method as well, since the data subscription of the universe members are handled automatically: when the security is in the universe, it will be subscribed; if it leaves the universe, it won't be subscribed anymore.
If you need to track or iterate the member of the universe, you can do the below:
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.
Dharmesh Khalasi
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!