Navigation

    Quantiacs Community

    • Register
    • Login
    • Search
    • Categories
    • News
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    How to get stocks in SP500 index at a given time

    Support
    2
    4
    277
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      buyers_are_back last edited by buyers_are_back

      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).

      1 Reply Last reply Reply Quote 0
      • S
        stefanm last edited by

        @buyers_are_back Hi,

        You can use is_liquid field 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_liquid field:

        ### 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
        B 1 Reply Last reply Reply Quote 0
        • B
          buyers_are_back @stefanm last edited by

          @stefanm said in How to get stocks in SP500 index at a given time:

          is_liquid_spec = is_liquid.sel(time=date)
          members_spec = is_liquid_spec.coords["asset"][is_liquid_spec == 1.0].asset.values

          Thanks for the reply! I have some further questions.

          1. Is it the case that the dataset does not contain all symbols in the index? If I plot the number of stocks it started from around 350 then increases to 500.

          c80c9110-826a-4349-8125-f3641fad0e09-image.png

          1. There are some symbols and their counterparts with suffix ~1, for instance NAS:FISV and NAS:FISV~1, what does it mean?

          f16737ac-577b-44ea-b698-fdd1164f4dd9-image.png

          S 1 Reply Last reply Reply Quote 0
          • S
            stefanm @buyers_are_back last edited by

            @buyers_are_back Hi,

            Regarding your first question, yes, that is correct. As we look more into the past, it is more difficult to get data for companies which have been index members but don't exist anymore, for example. This is also related to your second question - symbols with '~1' are in almost all cases, the same companies with the same ticker symbol, but with different ISIN (International Securities Identification Number). For instance, SanDisk company ("NAS:SNDK") was standalone public company until 2016, when Western Digital acquired SanDisk. In 2025 company spinoff, SanDisk re-emerged on the Nasdaq as an independent public company, with the same ticker as it was ('SNDK'), but with different ISIN (considered as different company).
            Those symbol pairs, should not have an intersection in membership ("is_liquid" field should not be 1.0 for both at the same time), otherwise it could be mistake by provider.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB | Contributors
            • Documentation
            • About
            • Career
            • My account
            • Privacy policy
            • Terms and Conditions
            • Cookies policy
            Home
            Copyright © 2014 - 2021 Quantiacs LLC.
            Powered by NodeBB | Contributors