How to get stocks in SP500 index at a given time
-
The data has more than 500 stocks. I know it includes stocks that used to belong to SP500. For instance for (2026, 2, 24):
from qnt.data import stocks_load_spx_list len(stocks_load_spx_list(min_date='2026-02-24', max_date='2026-02-24'))gives 842.
Filtering NaNs gives me 658 stocks, which is still more than 500.
For a given date, I'd like to exclude the weights for those that are out (no forward-looking involved).
-
@buyers_are_back Hi,
You can use
is_liquidfield from spx dataset to filter out weights allocated to not members of S&P500 at given point in time:from qnt.data import stocks_load_spx_data spx_data = stocks_load_spx_data(min_date="2006-01-01") is_liquid = spx_data.sel(field="is_liquid") final_weights = your_weights * is_liquid ### weights for given date (weights_spec) date = "2026-02-24" weights_spec = final_weights.sel(time=date)The number 842 represents total number of assets that have been members of S&P500 index at some point in time (from given dataset), and 658 shows number of assets that are still active on market (have OHLC prices), but only ~500 are index constituents in that point in time.
To get the list of index members on certain date, just filter
is_liquidfield:### liquidity field values for given date is_liquid_spec = is_liquid.sel(time=date) members_spec = is_liquid_spec.coords["asset"][is_liquid_spec == 1.0].asset.values