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
1 0 0 1

How can I reference data from -120 days ago from a specific date using the get data or get history function in Python?

Hi team,

please find the case 11627819,

clients query is How can I reference data from -120 days ago from a specific date using the get data or get history function in Python? In my current code, when the start date is set to '-120', I think the data pulls 120 days' worth of data before t=0, where 0 is the current date. How would I be able to pull 120 days' worth of data before a specified date?

Please do assist on this.


Thanks,

python
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
84.8k 289 53 77

@Babyshyamili.S

You can use timedelta in Python to calculate -120 days ago from a specific date. For example, the code looks like this.

from datetime import datetime, timedelta, date

specific_date = date(2022, 9, 13)
start_date = specific_date - timedelta(days=120)
print(specific_date)
print(start_date)
2022-09-13
2022-05-16

Then, those dates can be used with the get_data and get_history methods.

For example:

rd.get_data(
    universe=['LSEG.L', 'VOD.L'],
    fields=['TR.PriceClose.Date','TR.PriceClose'],
    parameters = {'SDate': start_date.strftime("%Y-%m-%d"),'EDate':specific_date.strftime("%Y-%m-%d"), 'Curn': 'CAD'}
)


rd.get_history(universe=["VOD.L"],start=start_date, end=specific_date, interval="1D")
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
15.3k 32 5 10

Hi @Babyshyamili.S ,

is this what you're looking for? the parameter 'count':

count : int, optional
            The maximum number of data returned. Values range: 1 - 10000

For example

df=rd.get_history(universe="LSEG.L", interval="daily", end="2021-08-01", count=120)
df

1664346899756.png

I hope this helps and please let me know in case you have any further questions


1664346899756.png (64.7 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.

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.