How to get close price in USD eikon data API

Hi image

I´ve read the other post, but my code doesn't work, could you tell me what is wrong?

I am using the following code?

'''

pko,e = ek.get_data("PALK-MYID-P1",["TR.PriceClose(SDate='2020-09-01', EDate='2020-09-14').Date"

,"TR.PriceClose(SDate='2020-09-01', EDate='2020-09-14', curn='USD')"])

pko

'''

Best Answer

  • Field TR.PriceClose does not exist for RIC PALK-MYID-P1. Try

    ek.get_data('PALK-MYID-P1',['TR.CLOSEPRICE.date','TR.CLOSEPRICE'],
                {'SDate':'2020-09-01', 'EDate':'2020-09-14'})

    For a brief explanation of the difference between TR.PriceClose and TR.CLOSEPRICE see the answer on this thread.

Answers

  • Hi Alex

    It doen´t work to change from MYR price to USD.

    '''

    bmd,e = ek.get_data('FCPOc3',['TR.CLOSEPRICE.date','TR.CLOSEPRICE'],

    {'SDate':'2020-09-01', 'EDate':'2020-09-14', curn="USD"})

    bmd

    '''

  • Correct. As mentioned in the answer on the thread I referenced, currency conversion is not available for TR.CLOSEPRICE. To convert timeseries of close prices for this future to another currency you need to retrieve the timeseries of exchange rate, merge the two timeseries and apply the exchange rate to the close price of the future.

    df1, err = ek.get_data("FCPOc1",
                           ["TR.CLOSEPRICE.date","TR.CLOSEPRICE"],
                           {'SDate':'2020-09-01', 'EDate':'2020-09-14'})
    df2, err = ek.get_data("MYR=",
                           ["TR.BIDPRICE.date","TR.BIDPRICE"],
                           {'SDate':'2020-09-01', 'EDate':'2020-09-14'})
    df = df1.merge(df2, how='left', on='Date')
    df['Date'] = pd.to_datetime(df['Date'])
    df.set_index('Date', inplace=True)
    df.rename(columns={'Bid Price':'USDMYR Exch rate'}, inplace=True)
    df.drop(['Instrument_x', 'Instrument_y'], axis=1, inplace=True)
    df['Close Price USD'] = df['Close Price'] / df['USDMYR Exch rate']
    df