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()1
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()
-
Perhaps you could use Realty Income Trust0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛