Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
3 0 0 2

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.

#technologyrefinitiv-data-librariesrefinitiv-data-platform-eikon
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
6k 18 2 8

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'})
df

screenshot-2024-07-08-at-131823.png

For 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


screenshot-2024-07-08-at-131928.png


Hope this helps.


Best regards,

Haykaz


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
3 0 0 2

screenshot-2024-07-08-175615.pngscreenshot-2024-07-08-175504.png


I believe the screenshot shared by you is of Ownership Shareholder reports, I want to fetch data for Ownership Summary.


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

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.

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)]


1720509382714.png


Now I want your help in getting the same for last month/quarter/year (historically) data.

Upvotes
3 0 0 2

@aramyan.h

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)]


1720509382714.png


Now I want your help in getting the same for last month/quarter/year (historically) data.


1720509382714.png (49.4 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
6k 18 2 8

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'})
df

Please 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

screenshot-2024-07-09-at-095504.png


Best regards,

Haykaz


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
3 0 0 2

@haykaz.aramyan

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']

)


1720517818668.png


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:

1720517920345.png


1720517818668.png (34.6 KiB)
1720517920345.png (53.2 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
3 0 0 2

@haykaz.aramyan

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:

1720522893197.png





1720522851732.png



1720522893197.png (75.6 KiB)
1720522851732.png (31.1 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
6k 18 2 8

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_pivot3

screenshot-2024-07-10-at-104003.png

Best regards,

Haykaz


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @haykaz.aramyan

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'],

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_pivot3

screenshot-2024-07-10-at-132627.png


Best regards,

Haykaz

Upvotes
6k 18 2 8

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' 

]

)
df5

screenshot-2024-07-11-at-115743.png

Best regards,

Haykaz


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.