Rhistory in Python for various Instrument Type Codes

I have a list of RICS for which I would like to acquire the historic closing prices. They have various 'Instrument Type Code's (OPF, ORD, ELN, DEPOSITSHS, ADR, UNT, DEBENT, PREFERRED, SENIOR, CEF, ETFB, CUM, MMF, ETFE and ETFC).

Basically I'm looking for the Date & OHLC for each of the RICS. I understand that not all of the RICS would have OHL because of the type of security, but all of the RICS should likely have a "CLOSE" and corresponding date.

Using the get_data() in Python, I get a majority of the dates and OHLC. I do not get daily Date, Close for the OPF(Open Ended Mutual Funds).

    ts = pd.DataFrame()
chunk_size = 50
for i in range(0, len(RICS), chunk_size):
rics = RICS[i : i + chunk_size]
df, err = ek.get_data(rics,
['TR.CLOSEPRICE.date','TR.CLOSEPRICE',
'TR.HIGHPRICE','TR.LOWPRICE',
'TR.OPENPRICE','TR.ACCUMULATEDVOLUME'],
{'SDate':'-13Y', 'EDate':'0D'})
ts = ts.append(df, sort=False)
ts


In Eikon Excel, I'd used this formula to match the Date and CLOSE of the OPF types with other instrument types...If RIC Instrument Type Code is "OPF" =RHistory("TPINX.O","NAV.Value","START:2013-05-27 INTERVAL:1D",,"SORT:DESC"), Otherwise, =RHistory("IBM",".Close","START:2013-05-27 INTERVAL:1D",,"SORT:DESC")

I'm looking to replicate this in Python for all the RICS.


I tried using get_timeseries(), but I get a "Backend error. 500 Internal Server Error". and "raise RDPError(server_response["ErrorCode"], error_message)"

data = pd.DataFrame()   
chunk_size = 50
for i in range(0, len(RICS), chunk_size):
rics = RICS[i : i + chunk_size]

df, err = ek.get_timeseries(RICS,
fields='CLOSE',
start_date='2018-02-12',
end_date='2018-02-28',
interval='daily')
data = data.append(df, sort=False)
data

Any help on this?

Thanks

Best Answer

  • aramyan.h
    Answer ✓

    Hi @eric.sams ,


    The field name seems to be VALUE which needs to be provided within brackets, see below:

    df = ek.get_timeseries('AHHYX.O',  
    fields=['VALUE'],
    start_date='2018-02-12',
    end_date='2018-02-28',
    interval='daily')
    df


    screenshot-2023-06-01-at-112247.png


    I would also suggest using our latest RD Libraries for Python for this request which returns more fields for this instrument

    df = rd.get_history('AHHYX.O',  
    start='2018-02-12',
    end='2018-02-28',
    interval='1D')
    df

    screenshot-2023-06-01-at-112408.png

    Hope this helps.


    Best regards,

    Haykaz

Answers

  • Hi @eric.sams ,


    Thank you for your question. It would be useful if you share with us at least some of the RICs (a couple of working and a couple which didn't work) so we can debug on our end.


    Best regards,

    Haykaz

  • Hi @eric.sams ,

    There are numerous reasons why an HTTP request may occasionally fail. If this happens randomly and infrequently, a simple workaround is to catch the error and re-request the data. If this happens frequently or if you're able to consistently reproduce the problem, please provide an information for further investigation as requested by my colleague.

  • Here's a sampling of the Instrument Type Codes:rics.jpg

    I cannot get historic NAV pricing on the "OPF" Instrument Type Code using get_data() in Python.

    Here are more RICs of "OPF" types:

    LP40125407 AHHYX
    LP40006010 ACERX
    LP40000318 ACEIX
    LP40019497 OIBAX
    LP40005522 OPSIX
    LP40002057 OPIGX
    LP40007914 MGFIX
    LP40112832 ARSIX
    LP40199311 AUEIX
    LP40216560 CIPNX
    LP40187649 CIPIX
    LP40197706 HHDFX

  • When I run:


    df = rd.get_history('AHHYX.O', start='2018-02-12', end='2018-02-28', interval='1D') df

    I receive "AttributeError: module 'refinitiv.dataplatform' has no attribute 'get_history'


    My Code:

    import refinitiv.dataplatform as rd
    import pandas as pd
    import numpy as np
    import datetime

    rd.open_desktop_session('xxxxxxxxxxxxxxxxxxx4922')
    df = rd.get_history('AHHYX.O',  
    start='2018-02-12',
    end='2018-02-28',
    interval='1D')
    df
    ---------------------------------------------------------------------------
    AttributeError Traceback (most recent call last)
    Untitled-1.ipynb Cell 2 in ()
    ----> 1 df = rd.get_history('AHHYX.O',
    2 start='2018-02-12',
    3 end='2018-02-28',
    4 interval='1D')
    5 df

    AttributeError: module 'refinitiv.dataplatform' has no attribute 'get_history'



  • Hi @eric.sams ,


    In your example you are using Refinitiv Data Platform instead of RD Libraries. Please see the compete code with inports below:


    import refinitiv.data as rd
    rd.open_session()
    df = rd.get_history('AHHYX.O',
    start='2018-02-12',
    end='2018-02-28',
    interval='1D')
    df

    Before that you need to pip install refinitiv-data if not already.


    Best regards,

    Haykaz