question

Upvotes
Accepted
11 1 1 3

Download the stock daily prices and total return together with date sorted

Hi all,

I am trying to download the daily prices and total return of a list of RICs. However, when I tried by using the following codes, the sorted dates of these two variables are opposite. How to modify the code to combine the date?

Many thanks

ric = df['ric'].astype(str).tolist()

df, e = ek.get_data(ric, 
                    ['TR.PriceClose(Curn=USD)','TR.TotalReturn','TR.PriceClose.calcdate','TR.TotalReturn.date'],
                     {'SDate': '2024-01-01',
                     'EDate': '2024-02-10','Frq':'D'})
df1710345601429.png
eikonpython#technologyapi#content
1710345601429.png (23.0 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
Upvotes
Accepted
7.2k 23 3 6

Hi @jiayin.meng.20 ,


I would advise updating to the new library, have you had a look at it?

import refinitiv.data as rd
rd.open_session()

df = rd.get_data(
    universe=["LSEG.L", "VOD.L"],
    fields=['TR.PriceClose(Curn=USD)','TR.TotalReturn','TR.PriceClose.calcdate','TR.TotalReturn.date'],
    parameters={
        "SDate": '2024-01-01',
        "EDate": '2024-02-10', # "Curn": "EUR",
        'Frq':'D'})
df

1710347262956.png



I'd actually advise the get_history function instead.


1710347262956.png (41.1 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @jonathan.legrand


Thanks for answering. However, the order of the date of total return and daily price seems also different. Could you please provide a code to make the order of these dates the same? For example both from 2024-01-01 to 2024-01-31

Hi @jiayin.meng.20 ,

Are you asking for the dataframe rows' order to be inverted? If so, I believe the following can help:
https://stackoverflow.com/questions/35240528/reverse-dataframes-rows-order-with-pandas

Hi @jonathan.legrand


Thanks. But I am not sure if this is what I am asking. I would like to add a `sort` function after the retrieve of the data. Take my initial picture as an example, I want to retrieve the daily price and total return of `000002.SZ` from 2024.01.01 to 2024.02.10. However, the results show the order of daily price is from 2024.01.01 to 2024.02.10, while the order of total return is from 2024.02.10 to 2024.01.01. I would like to merge the two dates into a one. I know I can download them separately and merge them accordingly. But as there are a large amount of RICs, I would like to know is there a function that I can **sort the date** when I retrieve the values?


Many thanks

Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.