Fetching all companies in an index

Hide code cell content
import refinitiv.data as rd

rd.open_session()
/home/runner/.local/share/virtualenvs/refinitiv-data-python-cookbook-I-HIyNf4/lib/python3.10/site-packages/refinitiv/data/_access_layer/session.py:71:FutureWarning: 
You open a platform session using the default value of the signon_control parameter (signon_control=True).
In future library version v2.0, this default will be changed to False.
If you want to keep the same behavior as today, you will need to set the signon_control parameter to True either in the library configuration file
({'sessions':{'platform':{'your_session_name':{'signon_control':true}}}}) or in your code where you create the Platform Session.
These alternative options are already supported in the current version of the library.
<refinitiv.data.session.Definition object at 0x7f0ff040d060 {name='rdp'}>

You can use the Refinitiv Data Library for Python to retrieve metadata about all of the companies in a stock index.

To do so, pass the index’s Refinitiv Instrument Code with a 0# prefix to the fundamental_and_reference component of package’s content submodule.

The method requires that you specify at least one field to retrieve for each company, in addition to its code. Here’s how to retrieve the name and ticket symbol of each of the 30 entries in the Dow Jones Industrial Average:

rd.content.fundamental_and_reference.Definition(
    universe=["0#.DJI"],
    fields=[
        "TR.CommonName",
        "TR.TickerSymbol"
    ],
).get_data().data.df
Instrument Company Common Name Ticker Symbol
0 GS.N Goldman Sachs Group Inc GS
1 NKE.N Nike Inc NKE
2 CSCO.OQ Cisco Systems Inc CSCO
3 JPM.N JPMorgan Chase & Co JPM
4 DIS.N Walt Disney Co DIS
5 INTC.OQ Intel Corp INTC
6 DOW.N Dow Inc DOW
7 MRK.N Merck & Co Inc MRK
8 CVX.N Chevron Corp CVX
9 AXP.N American Express Co AXP
10 VZ.N Verizon Communications Inc VZ
11 HD.N Home Depot Inc HD
12 MCD.N McDonald's Corp MCD
13 UNH.N Unitedhealth Group Inc UNH
14 AMZN.OQ Amazon.com Inc AMZN
15 KO.N Coca-Cola Co KO
16 JNJ.N Johnson & Johnson JNJ
17 MSFT.OQ Microsoft Corp MSFT
18 HON.OQ Honeywell International Inc HON
19 CRM.N Salesforce Inc CRM
20 PG.N Procter & Gamble Co PG
21 IBM.N International Business Machines Corp IBM
22 MMM.N 3M Co MMM
23 AAPL.OQ Apple Inc AAPL
24 WMT.N Walmart Inc WMT
25 CAT.N Caterpillar Inc CAT
26 AMGN.OQ Amgen Inc AMGN
27 V.N Visa Inc V
28 TRV.N Travelers Companies Inc TRV
29 BA.N Boeing Co BA

Note

In Refinitiv terminology, the 0# prefix is known as a “chain.” It is used to identify a group of instruments that share a common characteristic, such as being part of an index.

Hide code cell content
rd.close_session()