how to calculate daily return for group of stocks in a dataframe & put output in different column

Hello,

I have a list of some say 8 stocks in a dataframe from a sample universe of 4000 stocks. The stocks are listed by their RIC. I want to calculate the daily return & derive that output in a different column. the data frame sample will look like below: RICS on left side & prices on right side. How can Eikon API have a time series function code to get that output.? Can someone help & guide how to calculate the returns in pandas. Help is much appreciated. Tks R

1725629374083.png

Tagged:

Best Answer

  • raksina.samasiri
    Answer ✓

    Hi @rupa ,

    get_timeseries method can only return price history in the currency in which the instrument is traded. If your instruments are stocks or indices you can use get_data method with TR.PriceClose field, which can return price history in the currency of your choice:

    df, err = ek.get_data('AAPL.O',['TR.PriceClose.date','TR.PriceClose'], {'SDate':'2024-05-01', 'EDate':'2024-07-01', 'CURN':'EUR'})
    display(df)

Answers

  • @rupa Thanks for your question so you should create another column and calculate the difference between the two columns - something like:

    closePriceDF1['Daily Change'] = closePriceDF1['2024-08-22'] - closePriceDF1['2024-08-21']

    that should calculate the difference. You can also calculate a % change by altering the formula slightly. I. hope this can help.


  • rupa
    rupa Newcomer

    hello, thanks Jason.

    i was able to change formula to get %.

    i have a query on that .....As the stocks are in different currencies, what code can be used in a function:

    1. to get the currency
    2. convert all those in to home currency?


    thanks in advance


    RS

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.