target price of S&P500 listed firm

How to get all target price of S&P500 listed firm in from 2000 to 2022?
Best Answer
-
Hi @pan.yiming ,
First create a list of date you want to retrieve the data
import pandas as pd
import time
import refinitiv.data as rd
rd.open_session()
m = 'Dec'
start_y = 2000
end_y = 2022
start = pd.to_datetime(f'{m}{start_y}', format='%b%Y')
end = pd.to_datetime(f'{m}{end_y+1}', format='%b%Y')
date_list = pd.date_range(start, end, freq='Y')
date_listThen from each date, use get_data function to retrieve the list of constituents on that date
for date in date_list:
print(date)
index_data = rd.get_data(f'0#.SPX({date.strftime("%Y%m%d")})',['TR.RIC'])
display(index_data)
time.sleep(1)After you retrieve the constituents, depending on which format of the data you want, you can retrieve the target price data with get_data function.
Please let me know in case you have any further question
0
Answers
-
Hi @pan.yiming ,
Is this what you're looking for?
here's to get the S&P500 constituents list as of 31 December 2022, you could loop through the dates that you want the data and put the date in the bracket right after the RIC name (replace the date 20221231 in the code below)
index_data = rd.get_data('0#.SPX(20221231)',['TR.RIC', 'TR.PriceTargetMedian','TR.PriceTargetMean','TR.PriceTargetNumIncEstimates'])
index_dataHowever, there's an article Building historical index constituents, which explain the process of building historical constituents of a market index, underscoring its importance for investors, researchers, and various participants in the financial markets.
0 -
0
-
Or you could create a Python dictionary with the list of Constituents of each date, then use this dict for further data retrieval
for example,
constituents_dict = {}
for date in date_list:
print(date)
index_data = rd.get_data(f'0#.SPX({date.strftime("%Y%m%d")})',['TR.RIC'])
constituents_dict[date] = index_data['RIC'].to_list()
time.sleep(1)The Python dict will be in format of {Date: [list of Constituents], ...}
0 -
Thank you so much. Do you know how to get the Eikon data API key?
0 -
Hi @pan.yiming ,
You're welcome.
The code I suggested is using Refinitiv Data Library for Python, which is the newestand strategic python library for retrieving data from the Data Platform. More detail can be found in article Summary of Common LSEG Refinitiv APIs
You may follow the quick start guide to start using the Data Library and the example code can be found here
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 684 Datastream
- 1.4K DSS
- 615 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 249 ETA
- 554 WebSocket API
- 37 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 643 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 26 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 192 TREP Infrastructure
- 228 TRKD
- 915 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛