k0rnik
k0rnik

Reputation: 502

Bloomberg APIs - historical index members in Python

I'm trying to get index members using Bloomberg APIs in Python. I have no issues getting current constituents, but I want a historical list (example: what where Russell 1000 or S&P 500 constituents as of Q1 1995).

To get the current index members I can use following:

In excel I can use INDX_MEMBERS to get the constituents:

=BDS("Index Ticker", INDX_MEMBERS)

In Python:

import pybbg

def Main():
    bbg = pybbg.Pybbg()
    IndexConst = bbg.bds('IndexName', 'INDX_MEMBERS')

or:

from tia.bbg import LocalTerminal

resp = LocalTerminal.get_reference_data(index_ticker + ' INDEX', 'INDX_MEMBERS')
members = resp.as_frame().iloc[0,0]

Question is how can I get historical index members/constituents. For example I would generate quarterly dates and then I want to know list of constituents for each date.

['2020-06-30', '2020-03-31', '2019-12-31', '2019-09-30', '2019-06-30', '2019-03-31', '2018-12-31' ... '1980-06-30',]

I've tried many solutions, including one below where I'm getting an empty frame:

from tia.bbg import LocalTerminal

date_start = datetime.date(2010,6,28)
date_end = datetime.date(2020,6,28)

members_russell1000_3 = LocalTerminal.get_historical('RIY Index', 'INDX_MEMBERS',start=date_start, end=date_end,).as_frame()

or the solution below, where regardless of date (now or 20 years ago) I'm receiving the same list of constituents:

from xbbg import blp

members =  blp.bds('RIY Index', 'INDX_MEMBERS', DVD_Start_Dt=k[1], DVD_End_Dt=k[1])

Variable Explanation to above examples:

Alternatively I would be happy if I could get historical list of changes to index constituents with dates (I already have current constituents)

Upvotes: 2

Views: 4817

Answers (2)

Bm_2023
Bm_2023

Reputation: 1

I've found that the below works
blp.bds('RIY Index', "INDX_MWEIGHT", END_DATE_OVERRIDE="20210101")
and gives the same results as an excel query
=BDS("RIY Index", "INDX_MWEIGHT_HIST", "END_DATE_OVERRIDE",'20210101')
Alternatively using "INDX_MWEIGHT_PX" gives the actual weight and current price values also.

Upvotes: 0

assylias
assylias

Reputation: 328608

You need to use the INDX_MWEIGHT_PX field and the END_DATE_OVERRIDE override (date format: yyyymmdd). It is a reference data request, so probably bds and not bdh in the python library but I've never used it, so not 100% sure and you may need to try a few solutions until you find the correct one.

Upvotes: 1

Related Questions