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)
Best Answer
-
Hi @ken03 ,
To retrieve Price Close for each Dividend Ex Div, you need to split into 3 steps:
- request Dividend Ex date
- request Price Close for each Div Ex date
- 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()0
Answers
-
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.
0 -
- 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()
- This should be easy to fix if you provide an example.
0 - 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()
-
0
Categories
- All Categories
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 33 Data Model Discovery
- 682 Datastream
- 1.4K DSS
- 613 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 248 ETA
- 552 WebSocket API
- 37 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.8K Refinitiv Data Platform
- 625 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 26 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 191 TREP Infrastructure
- 228 TRKD
- 915 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 83 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛