How can I reference data from -120 days ago from a specific date using the get data or get history f

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,

Tagged:

Best Answer

  • Jirapongse
    Jirapongse admin
    Answer ✓

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

Answers

  • 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