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 -
Yes, it is. Could you please share the complete code with me?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
- 6 AHS
- 39 Alpha
- 162 App Studio
- 4 Block Chain
- 5 Bot Platform
- 17 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 370 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 60 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛