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

Best Answer

  • @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

Answers