Hi,
Any reason why the number of sp500 constituents drop over time maybe the way i'm calling it's not good.
Thanks for your help
class StandardizedUnexpectedEarnings(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 3, 1) # Set Start Date. Warm up for first 36 months
self.SetEndDate(2024, 6, 6) # Set End Date
self.SetCash(100000) # Set Strategy Cash
self.add_universe_selection(
ETFConstituentsUniverseSelectionModel("SPY", universe_filter_func=self.etf_constituents_filter)
)
def etf_constituents_filter(self, constituents: List[ETFConstituentUniverse]) -> List[Symbol]:
if self.time.month == self.month:
return Universe.Unchanged
self.month = self.time.month
self.debug(self.time)
self.debug(len(list(constituents)))
return Universe.Unchanged
That my logs output :
2020-03-01 00:00:00 504
2020-04-01 00:00:00 503
2020-05-01 00:00:00 504
2020-07-01 00:00:00 505
2020-08-01 00:00:00 504
2020-11-03 00:00:00 503
2021-04-01 00:00:00 504
2021-05-01 00:00:00 503
2021-07-01 00:00:00 502
2021-08-03 00:00:00 501
2022-03-01 00:00:00 500
2022-04-01 00:00:00 1000
2022-05-03 00:00:00 498
2022-11-01 00:00:00 496
2022-12-01 00:00:00 497
2023-01-04 00:00:00 496
2023-02-01 00:00:00 497
2023-03-01 00:00:00 496
2023-04-01 00:00:00 497
2023-06-01 00:00:00 498
2023-07-01 00:00:00 497
2023-09-01 00:00:00 496
2023-11-01 00:00:00 495
2024-04-02 00:00:00 496
2024-05-01 00:00:00 495
Mia Alissi
The number of constituents in an ETF like SPY can change over time due to various factors such as corporate actions (mergers, acquisitions, bankruptcies), changes in the index composition, or data issues.
In your case, it seems like there might be a data issue. A similar issue was reported in the QuantConnect forum where a user noticed that the number of constituents in SPY was significantly less than 500 on some days. The QuantConnect team acknowledged this as a data issue and provided a link to track the progress of resolving it.
Here is the relevant extract from the forum discussion:
I recommend you to follow the link provided in the forum discussion to track the progress of the data issue. If the issue persists, you might want to report it to the QuantConnect team.
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.
Ruben Ohayon
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!