What are correct parameters to fetch historical data for provided fields?

Hi,

I want to fetch the historical data for below fields. What is the correct way to fetch the historical data for a specified Date from history? Please find below the fields and code to replicate the results-

fields = ['SetLabel(TR.InstrStatLocationId(StatType=3),location),SetLabel(TR.InstrStatLocation(StatType=3),locationName)',

'SetLabel(TR.CategoryInvestorCount(StatType=3),investorCount),SetLabel(TR.CategoryOwnershipPct(StatType=3),os)',

'SetLabel(TR.InstrStatCatSharesHeld(StatType=3),position)','SetLabel(TR.InstrStatCatShrsHldVal(StatType=3),heldValue)','Curn=USD']

ric = ['GE', 'TT']

def fetch_refinitv_data(universe, field_input):

rd.open_session()

df = rd.get_data(universe=universe, fields=field_input)

rd.close_session()

return df

df = fetch_refinitv_data('GE',fields)

df


Would appreciate any help on the necessary changes to the above code required to fetch the historical data.


Thanks in advance

Best Answer

  • nick.zincone
    Answer ✓

    Hi @atul.arya

    I would suggest to reach out to the Workspace Helpdesk - F1 (Get Help & Support) to get the exact request to retrieve the data. What they will do is provide the formula to get the specific data you are after. The formula they provide will work within Excel but you can easily convert it to use the Data Library.

    For example, this the formula I'm using to get some of the data you are after:

    rd.get_data(
    universe=["GE"],
    fields=['TR.InstrStatLocationId.date', 'TR.InstrStatLocationId', 'TR.InstrStatLocation',
    'TR.CategoryInvestorCount', 'TR.CategoryOwnershipPct', 'TR.InstrStatCatSharesHeld',
    'TR.InstrStatCatShrsHldVal'],
    parameters={'StatType': 3, 'SDate': "2024-01-01", 'EDate': "2024-07-01"}
    )

    1720532873567.png

    Now, looking at your function 'fetch_refinitv_data()', you are opening a session every time you call this function. You should not do this but instead do it once at the start of your application. Also, I would suggest you use CodeBook to play with the formulas before you attempt to write a complete application. Within CodeBook, you should see a number of examples as a guide to help you play and experiment with basic data requests. From there, you can begin to code out your complete application.

    Within CodeBook, on the top left, choose __Examples__/ and navigate to the Refinitiv Data Library section. See below.

    1720532738535.png


Answers

  • Thank you @nick.zincone for the solution and suggestions.


    It worked on Style, Location, and Rotation as they are associated with a StatType. We used

    'TR.InstrStatTypeValueId.date' for style, 'TR.InstrStatLocationId.date' for location, 'TR.InstrStatTypeValueId.date' for rotation to get the date columns


    How to do the same for Turnover? Here is the code for

    'OS', 'POSITION', 'HELDVALUE'

    are also different

    TR.PctOfSharesOutHeld, TR.SharesHeld, TR.SharesHeldValue

    and not ('TR.CategoryOwnershipPct', 'TR.InstrStatCatSharesHeld', 'TR.InstrStatCatShrsHldVal')


    I was using it in this way and had to create a pivot then.

    fields = ['SetLabel(TR.OwnTrnverRating,turnoverRating)','SetLabel(TR.PctOfSharesOutHeld,os)','SetLabel(TR.SharesHeld,position)',
    'SetLabel(TR.SharesHeldValue,heldValue)', 'Curn=USD']
    turnover = fetch_refinitv_data(ric,fields)

    turnover_pivot = pd.pivot_table(turnover, values= ['OS', 'POSITION', 'HELDVALUE'], index = ['Instrument', 'TURNOVERRATING'], aggfunc = 'sum')
    turnover_pivot

    1720561084493.png

    So please help me to fetch the last 3 months of Turnover data.

    Thank you,

  • Thank you @nick.zincone for the solution and suggestions.


    It worked on Style, Location, and Rotation as they are associated with a StatType. We used

    'TR.InstrStatTypeValueId.date' for style, 'TR.InstrStatLocationId.date' for location, 'TR.InstrStatTypeValueId.date' for rotation to get the date columns


    How to do the same for Turnover? Here is the code for


    'OS', 'POSITION', 'HELDVALUE'

    are also different


    TR.PctOfSharesOutHeld, TR.SharesHeld, TR.SharesHeldValue

    and not ('TR.CategoryOwnershipPct', 'TR.InstrStatCatSharesHeld', 'TR.InstrStatCatShrsHldVal')


    I was using it in this way and had to create a pivot then.


    fields = ['SetLabel(TR.OwnTrnverRating,turnoverRating)','SetLabel(TR.PctOfSharesOutHeld,os)','SetLabel(TR.SharesHeld,position)','SetLabel(TR.SharesHeldValue,heldValue)', 'Curn=USD']turnover = fetch_refinitv_data(ric,fields) turnover_pivot = pd.pivot_table(turnover, values= ['OS', 'POSITION', 'HELDVALUE'], index = ['Instrument', 'TURNOVERRATING'], aggfunc = 'sum')turnover_pivot

    image


    So please help me to fetch the last 3 months of Turnover data.

    Thank you,

  • Hi @atul.arya

    Have you had a chance to reach out to the helpdesk as I suggested? This is there area of expertise - specifically around the suggestions of the data and fields to use.