question

Upvotes
Accepted
1 0 0 2

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

eikon#content
1725629374083.png (11.9 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.

Upvotes
Accepted
15.5k 33 5 10

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)
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.

Upvote
11k 22 6 9

@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.


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.

Upvotes
1 0 0 2

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

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.

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.