Fetching data of company level in python
Hi,
If I search for a given ric (GE), and go to Ownership tab. We get data like Top Investors, Investor Type, Breakdown, and Holding Concentration. I want to extract these for a company over time through a codebook in Python. How can I do that? Thank you for the help.
Best Answer
-
Hi @atul.arya ,
Upon further checking, we identified that you can actually use SDate and EDate in the request above, however, you may need to provide also the FRQ parameter (otherwise by default is is Day and that was why it was taking to long). See below:
df5 = rd.get_data(
universe = ['GE'],
fields = [
'SetLabel(TR.OwnTrnverRating(SDate=1Q, EDate=-6Q, FRQ=Q),turnoverRating)',
'SetLabel(TR.PctOfSharesOutHeld(SDate=1Q, EDate=-6Q, FRQ=Q),os)',
'TR.PctOfSharesOutHeld(SDate=1Q, EDate=-6Q, FRQ=Q).date',
'SetLabel(TR.SharesHeld(SDate=1Q, EDate=-6Q, FRQ=Q),position)',
'SetLabel(TR.SharesHeldValue(SDate=1Q, EDate=-6Q, FRQ=Q),heldValue)', 'Curn=USD'
]
)
df5Best regards,
Haykaz
0
Answers
-
Hi @atul.arya ,
You can use the following code to start with:
df=rd.get_data('GE',['TR.InvestorFullName,TR.PctOfSharesOutHeld,TR.InvestorType'], {'SDate':'2024-07-07'})
dfFor more fields you can search 'GE SHARE' in the search bar of Workspace. In the opened app, if you click on the question mark next to a field name (see below), it will open the formula from where you can see the field name used
Hope this helps.
Best regards,
Haykaz
0 -
I believe the screenshot shared by you is of Ownership Shareholder reports, I want to fetch data for Ownership Summary.
0 -
you are right, the screenshot is from Shareholders Report and the reason I shared it is you can find the field names from there.
I am afraid you can't get the summary views (table and the graphs) via API calls, however that is something you can do using python dataframe (pandas) and charting (plotly) libs based on the API response I shared above.
The only reason I shared the Shareholders view was to help you find more fields for the Ownership request.
0 -
Hi,
I was able to get that Ownership Summary data from the following code.
# LOCATION
import refinitiv.data as rd
import pandas as pd
b = ['SetLabel(TR.InstrStatLocationId,location),SetLabel(TR.InstrStatLocation,locationName)',
'SetLabel(TR.CategoryInvestorCount,investorCount),SetLabel(TR.CategoryOwnershipPct,os)',
'SetLabel(TR.InstrStatCatSharesHeld,position)','SetLabel(TR.InstrStatCatShrsHldVal,heldValue)','StatType=3','Curn=USD']
b_ = fetch_refinitv_data('GE',b)
region = ['North America', 'Europe', 'Asia / Pacific', 'Africa', 'Middle East', 'Latin America']
b_[b_['LOCATIONNAME'].isin(region)]
Now I want your help in getting the same for last month/quarter/year (historically) data.
0 -
Hi,
I was able to get that Ownership Summary data from the following code.
# LOCATION
import refinitiv.data as rd
import pandas as pd
b = ['SetLabel(TR.InstrStatLocationId,location),SetLabel(TR.InstrStatLocation,locationName)',
'SetLabel(TR.CategoryInvestorCount,investorCount),SetLabel(TR.CategoryOwnershipPct,os)',
'SetLabel(TR.InstrStatCatSharesHeld,position)','SetLabel(TR.InstrStatCatShrsHldVal,heldValue)','StatType=3','Curn=USD']
b_ = fetch_refinitv_data('GE',b)
region = ['North America', 'Europe', 'Asia / Pacific', 'Africa', 'Middle East', 'Latin America']
b_[b_['LOCATIONNAME'].isin(region)]
Now I want your help in getting the same for last month/quarter/year (historically) data.
0 -
Hi @atul.arya ,
The date is going to be governed through 'SDate' parameter under the rd.get_data call. See an example below based on which you can modify your code:
df=rd.get_data(universe = 'GE', fields = ['TR.InvestorFullName,TR.PctOfSharesOutHeld,TR.InvestorType', 'TR.PctOfSharesOutHeld.date'], parameters = {'SDate':'-6M'})
dfPlease note that I have added also a field named 'TR.PctOfSharesOutHeld.date' which will return the date next to the values.
Possible values for 'SDate' parameter can be:
- for month you can use '0M', '-1M', '-2M' etc
- for year - '0Y', '-1Y' etc.
- you can also specify a date under the 'SdDate' parameter like '2024-07-01'
Some more options below
Best regards,
Haykaz
0 -
Hi,
Thank you for this.
one more query:
I have written 3 different code: (-1M, no SDate parameter, 0M)
Second one (df1) matches with the refinitiv database. So how to validate this through SDate, also die to which I can not get say last 3 quarters data as it does nat match with 0M/-1M
rd.open_session()
df = rd.get_data(
universe = ['GE'],
fields = [
'SetLabel(TR.OwnTrnverRating(SDate=-1M),turnoverRating)',
'SetLabel(TR.PctOfSharesOutHeld(SDate=-1M),os)',
'SetLabel(TR.SharesHeld(SDate=-1M),position)',
'SetLabel(TR.SharesHeldValue(SDate=-1M),heldValue)', 'Curn=USD']
)
rd.open_session()
df1 = rd.get_data(
universe = ['GE'],
fields = [
'SetLabel(TR.OwnTrnverRating,turnoverRating)',
'SetLabel(TR.PctOfSharesOutHeld,os)',
'SetLabel(TR.SharesHeld,position)',
'SetLabel(TR.SharesHeldValue,heldValue)', 'Curn=USD']
)
rd.open_session()
df3 = rd.get_data(
universe = ['GE'],
fields = [
'SetLabel(TR.OwnTrnverRating(SDate=0M),turnoverRating)',
'SetLabel(TR.PctOfSharesOutHeld(SDate=OM),os)',
'SetLabel(TR.SharesHeld(SDate=0M),position)',
'SetLabel(TR.SharesHeldValue(SDate=0M),heldValue)', 'Curn=USD']
)
c_pivot = pd.pivot_table(df, values= ['OS', 'POSITION', 'HELDVALUE'], index = ['Instrument', 'TURNOVERRATING'], aggfunc = 'sum')
c_pivot2 = pd.pivot_table(df1, values= ['OS', 'POSITION', 'HELDVALUE'], index = ['Instrument', 'TURNOVERRATING'], aggfunc = 'sum')
c_pivot3 = pd.pivot_table(df3, values= ['OS', 'POSITION', 'HELDVALUE'], index = ['Instrument', 'TURNOVERRATING'], aggfunc = 'sum')
Second pivot matches:
0 -
Hi,
Thank you for the solution.
I have one more query:
Below is the same code for different Sdate:
1. SDate= -1Q
2, no SDate
3. SDate = 2024-06-30
(Also I checked with -1M, 0M, 0Q etc but none mached with the correct refiniitv databse). It matched with second scenario (with no SDate). So, I want to know on what SDate it will get matched with original data.
rd.open_session()
df = rd.get_data(
universe = ['GE'],
fields = [
'SetLabel(TR.OwnTrnverRating(SDate=-1Q),turnoverRating)',
'SetLabel(TR.PctOfSharesOutHeld(SDate=-1Q),os)',
'SetLabel(TR.SharesHeld(SDate=-1Q),position)',
'SetLabel(TR.SharesHeldValue(SDate=-1Q),heldValue)', 'Curn=USD']
)
rd.open_session()
df1 = rd.get_data(
universe = ['GE'],
fields = [
'SetLabel(TR.OwnTrnverRating,turnoverRating)',
'SetLabel(TR.PctOfSharesOutHeld,os)',
'SetLabel(TR.SharesHeld,position)',
'SetLabel(TR.SharesHeldValue,heldValue)', 'Curn=USD']
)
rd.open_session()
df3 = rd.get_data(
universe = ['GE'],
fields = [
'SetLabel(TR.OwnTrnverRating(SDate=2024-06-30),turnoverRating)',
'SetLabel(TR.PctOfSharesOutHeld(SDate=2024-06-30),os)',
'SetLabel(TR.SharesHeld(SDate=2024-06-30),position)',
'SetLabel(TR.SharesHeldValue(SDate=2024-06-30),heldValue)', 'Curn=USD']
)
c_pivot = pd.pivot_table(df, values= ['OS', 'POSITION', 'HELDVALUE'], index = ['Instrument', 'TURNOVERRATING'], aggfunc = 'sum')
c_pivot2 = pd.pivot_table(df1, values= ['OS', 'POSITION', 'HELDVALUE'], index = ['Instrument', 'TURNOVERRATING'], aggfunc = 'sum')
c_pivot3 = pd.pivot_table(df3, values= ['OS', 'POSITION', 'HELDVALUE'], index = ['Instrument', 'TURNOVERRATING'], aggfunc = 'sum')
display(c_pivot, c_pivot2, c_pivot3)
result:
0 -
Hi @atul.arya ,
The reason you are not getting the same results is perhaps because of the SDate usage for TR.OwnTrnverRating, which results in NAs for certain periods and then when you group the sums are differing (you can confirm the reasons for NAs with the HelpDesk if needed).
I have tried with 1Q and 1M and I did get the expected results (no SDate for TR.OwnTrnverRating), see below for 1Q:
df5 = rd.get_data(
universe = ['GE'],
fields = [
'SetLabel(TR.OwnTrnverRating,turnoverRating)',
'SetLabel(TR.PctOfSharesOutHeld(SDate=1Q),os)',
'SetLabel(TR.SharesHeld(SDate=1Q),position)',
'SetLabel(TR.SharesHeldValue(SDate=1Q),heldValue)', 'Curn=USD']
)
c_pivot3 = pd.pivot_table(df5, values= ['OS', 'POSITION', 'HELDVALUE'], index = ['Instrument', 'TURNOVERRATING'], aggfunc = 'sum')
c_pivot3Best regards,
Haykaz
1 -
Thank you for this.
what if when we want to pull last 3 Quarters.
I was using this (EDate=-2Q) and it is running from 22 mins;
fields=['TR.InstrStatTypeValueId.date', 'TR.InstrStatTypeValueId', 'TR.InstrStatTypeValue',
'SetLabel(TR.OwnTrnverRating,turnoverRating)',
'SetLabel(TR.PctOfSharesOutHeld(SDate=1Q,EDate=-2Q),os)',
'SetLabel(TR.SharesHeld(SDate=1Q,EDate=-2Q),position)',
'SetLabel(TR.SharesHeldValue(SDate=1Q,EDate=-2Q),heldValue)', 'Curn=USD'],0 -
Hi @atul.arya ,
I just confirmed with the team that you can't use SDate and Edate for this type of a request. The suggested option is to include same fields with different SDate. See below:
df5 = rd.get_data(
universe = ['GE'],
fields = [
'SetLabel(TR.OwnTrnverRating,turnoverRating)',
'SetLabel(TR.PctOfSharesOutHeld(SDate=1Q),os_1q)',
'SetLabel(TR.SharesHeld(SDate=1Q),position_1q)',
'SetLabel(TR.SharesHeldValue(SDate=1Q),heldValue_1q)', 'Curn=USD',
'SetLabel(TR.PctOfSharesOutHeld(SDate=-1Q),os_-1q)',
'SetLabel(TR.SharesHeld(SDate=-1Q),position_-1q)',
'SetLabel(TR.SharesHeldValue(SDate=-1Q),heldValue_-1q)', 'Curn=USD',
'SetLabel(TR.PctOfSharesOutHeld(SDate=-2Q),os_-2q)',
'SetLabel(TR.SharesHeld(SDate=-2Q),position_-2q)',
'SetLabel(TR.SharesHeldValue(SDate=-2Q),heldValue_-2q)', 'Curn=USD'
]
)
c_pivot3 = pd.pivot_table(df5, index = ['Instrument', 'TURNOVERRATING'], aggfunc = 'sum')
c_pivot3Best regards,
Haykaz
0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 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
- 367 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
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛