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
Accepted
1 0 0 0

How to replicate formula for TR.CategoryOwnershipPct in Codebook API?

Hi Team,

We are trying to replicate the formula and result below in Codebook API

Formula: =@TR("MSFT.O","TR.CategoryOwnershipPct","SDate=0CY EDate=-5CY StatType=1 CH=categoryvalue RH=effectiveTo")

microsoftteams-image-30.png

The closest we were able to get is by using this syntax and result:

import refinitiv.dataplatform.eikon as ek

ek.set_app_key('DEFAULT_CODE_BOOK_APP_KEY')


df, err = ek.get_data(
instruments = ['MSFT.O'],

fields = [
'TR.InstrStatTypeValue(Stattype=1)',
'TR.CategoryOwnershipPct(SDate=-1D,EDate=31-Dec-2022)', 'TR.InstrStatTypeValue.calcdate',
]
)

display(df.transpose())


microsoftteams-image-31.png

Please help with syntax on how to replicate the exact result as shown on the excel file. Thank you

eikon-data-apiworkspace-data-api#technologycodebook
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.

Hello @axelrose.bermillo

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?


If so please can you click the 'Accept' text next to the appropriate reply? This will guide all community members who have a similar question.

Thanks,


AHS

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,
AHS

1 Answer

· Write an Answer
Upvotes
Accepted
79.2k 251 52 74

@axelrose.bermillo

Thank you for reaching out to us.

Please try this one:

import refinitiv.dataplatform.eikon as ek

ek.set_app_key('DEFAULT_CODE_BOOK_APP_KEY')

df, err = ek.get_data(instruments = ['MSFT.O'],
                      fields = ['TR.CategoryOwnershipPct',
                                'TR.CategoryOwnershipPct.categoryvalue',
                                'TR.CategoryOwnershipPct.effectiveTo'],
                      parameters={'SDate':'0CY','EDate':'-5CY','StatType':1})


df.pivot(index='Effective To Date', columns='Category Value',values="Category Percent Of Traded Shares")

The code uses the pivot method to reshape the DataFrame organized by given index / column values.

The output is:

1695263776838.png


1695263776838.png (41.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.

Thank you so much Jirapongse for the fast and efficient response. Appreciate your assistance.

Hello @Jirapongse can you also share the code to get the data in a yearly interval? (Year end date in the format 31dec2020, 31dec2021, 31dec2022)

@axelrose.bermillo

You can use the Data Item Browser tool to list all available parameters of those fields.

1695353381767.png

Otherwise, you can contact the Eikon Excel support team and ask for the =TR formula that can be used to get the required data.

Then, we can convert the =TR formula to the Python code.

1695353381767.png (45.1 KiB)

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.