Historical Ownership Data with setlabel and fetch_refinitiv_data

Client 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 he wants to get data for last month/quarter/year (historically) data. When I tried copy and pasting this code in Codebook - I am getting error "

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/tmp/ipykernel_76/2082299371.py in <module>
11 'SetLabel(TR.InstrStatCatSharesHeld,position)','SetLabel(TR.InstrStatCatShrsHldVal,heldValue)','StatType=3','Curn=USD']
12
---> 13 b_ = fetch_refinitv_data('GE',b)
14
15 region = ['North America', 'Europe', 'Asia / Pacific', 'Africa', 'Middle East', 'Latin America']

NameError: name 'fetch_refinitv_data' is not defined"

Welcome!

It looks like you're new here. Sign in or register to get started.

Best Answer

  • nick.zincone
    nick.zincone admin
    Answer ✓

    Hi @mae.diaz

    If this is your first time working with the APIs, I would suggest you review the learning material within our Developer Portal. There are a number of resources for you to help understand basic examples. I'm assuming you are using Refinitiv Workspace - You can use CodeBook as a built-in development Jupyter environment - it will have plenty of examples within there.

    Have you tried the above example within Jupyter? It doesn't have to be defined within a function - I would personally start off really basic like you did above - don't make things fancy - simply do the minimum to get data then work from there.

Answers

  • Hi @mae.diaz

    When you run code within a Jupyter Notebook, you have the freedom to place code within cells. In your case, it appears you are executing a cell that contains the code: fetch_refiniti_data() but have not executed the cell where this function is defined.

  • Hi @nick.zincone how can I do it and may I ask for an example?

    Also, I have manually created code;

    import refinitiv.data as rd

    rd.open_session()

    df = rd.get_data(

    universe = ['GE'],

    fields = [

    'TR.InstrStatLocationId',

    'TR.InstrStatLocation',

    'TR.CategoryInvestorCount',

    'TR.CategoryOwnershipPct',

    'TR.InstrStatCatSharesHeld',

    'TR.InstrStatCatShrsHldVal',

    'TR.InvestorRegion'

    ],

    parameters = {

    'SDate': '0CY',

    'CH': 'date'

    }

    )


    display(df)

    Can the above code be the same function as what client had given earlier? Appreciate your help, thank you.

  • @nick.zincone, I have tried the first code above in Codebook which gave me the error message that I mention and check how you reference the b_ = fetch_refinitv_data('GE',b)

    region = ['North America', 'Europe', 'Asia / Pacific', 'Africa', 'Middle East', 'Latin America']

    b_[b_['LOCATIONNAME'].isin(region)].


    Instead, I manually created a code in CodeBK app - I'm using both Eikon and Workspace to get the data for "GE" and fields with "As of" parameter. All is set on my end, thanks again for checking my question. 1720557628439.png


Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.