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

# question

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,

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?

Thanks,

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Accepted
84.8k 289 53 77

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")```

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

15.3k 32 5 10

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```

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

1664346899756.png (64.7 KiB)

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.