Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
19 2 1 4

Time Series Yield

Hi i am currently trying to work out my own Dividend Yield.

I am using the following code to retrieve the daily price close and hope to index and match it with the dividend ex date.

df, err = ek.get_data(

instruments = [Instrument],

fields = [


'TR.PriceClose.date'

'TR.DivAdjustedNet',

'TR.DivAdjustedGross',

'TR.DivRecordDate',

'TR.DivPayDate',

'TR.DivExDate',

'TR.PriceClose'


],

parameters = {'SDate': '2021-10-01', 'EDate': 1,}

)


display(df)

#product#contenttime-series
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 @ken03 ,

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?
If so please can you click the 'Accept' text next to the appropriate reply? This will guide all community members who have a similar question. Or could you please provide the information requested for further suggestions.

Thanks,
AHS

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,
AHS

Upvote
Accepted
1.3k 3 2 4

Hi @ken03 ,

To retrieve Price Close for each Dividend Ex Div, you need to split into 3 steps:

  1. request Dividend Ex date
  2. request Price Close for each Div Ex date
  3. append Price Close to initial result

Example:

df, err = ek.get_data(
    instruments = [Instrument],
    fields = ['TR.DivAdjustedNet', 'TR.DivAdjustedGross', 'TR.DivRecordDate', 'TR.DivPayDate', 'TR.DivExDate'],
    parameters={'SDate': '2021-10-01', 'EDate': 1,}
)
prices = []
for d in df["Dividend Ex Date"]:
    price_df, err = ek.get_data(
        instruments = ["AAPL.O"],
        fields = ['TR.PriceClose.date', 'TR.PriceClose'],
        parameters={'SDate': d}
    )
    prices.append(price_df["Price Close"][0])
    print(price_df.to_string())

df["Price Close"] = prices
display(df)

To optimize, I'll recommend you to migrate from eikon to refinitv-data library and use asynchronous get_data_async() function to retrieve Price Close with a multi-treaded implementation:

import refinitiv-data as rd
import asyncio

session = rd.session.desktop.Definition(app_key="<YOUR APP KEY>").get_session()
rd.session.set_default(session)
session.open()

ex_div_dates = rd.get_data(
    universe=["AAPL.O"],
    fields=['TR.DivAdjustedNet', 'TR.DivAdjustedGross', 'TR.DivRecordDate', 'TR.DivPayDate', 'TR.DivExDate'],
    parameters={'SDate': '2021-10-01', 'EDate': 1,}
)
dates = [str(d.date()) for d in ex_div_dates["Dividend Ex Date"]]
ex_div_dates.set_index("Dividend Ex Date", inplace=True)

loop = asyncio.get_event_loop()
tasks = [loop.create_task(
    rd.content.fundamental_and_reference.Definition(
        universe=["AAPL.O"],
        fields=['TR.PriceClose.date', 'TR.PriceClose'],
        parameters={'SDate': d}).get_data_async()) for d in dates]

results = loop.run_until_complete(asyncio.gather(*tasks))
prices = pd.concat([r.data.df for r in results])
prices.sort_values(by=["Date"])
prices.set_index("Date", inplace=True)
final_result = pd.merge(ex_div_dates, prices, left_index=True, right_index=True))
display(final_result)

session.close()
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
19 2 1 4

Hi

1. Is refinitv-data library the new method for get_data?


2. i am trying to concat the data which i retrieve from get_data and get_time series for this purpose. but it seems that the date time format retrieved using each is different, for get_data it returns the date plus 0.00.00YZ and for get_time series it only returns the date, hence the different formating is affecting the concat function.


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. refinitiv-data is the new library to request or stream data with Refinitiv Data Platform, so yes, refinitiv-data.get_data() function replaces eikon.get_data()

  2. This should be easy to fix if you provide an example.
Perhaps you could use Realty Income Trust
Upvotes
19 2 1 4

@pf please try using the data from Realty Income Trust


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.

@ken03 Sorry but what's Realty Income Trust ?

Could you detail how you're using get_data and get_time series functions ?

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.