Fetching custom time ranges

Hide code cell content

import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)

import lseg.data as ld

ld.open_session()
<lseg.data.session.Definition object at 0x7f88a086a3c0 {name='rdp'}>

You can use the LSEG Data Library for Python to retrieve economic indicators for custom time ranges by passing a start and end date to the get_history function.

The inputs should be datetime.timedelta objects. The start argument is how many days before today to start the range, and the end argument is how many days before today to end the range.

This example retrieves the US unemployment rate for the last 20 years:

from datetime import timedelta

ld.get_history(
    "USUNR=ECI",
    # Note that this number is negative because it's in the past
    start=timedelta(days=-365 * 20),
    # `end` is set to zero to draw the latest numbers
    end=timedelta(days=0),
)
USUNR=ECI VALUE
Date
2005-10-31 5.0
2005-11-30 5.0
2005-12-31 4.9
2006-01-31 4.7
2006-02-28 4.8
... ...
2025-04-30 4.2
2025-05-31 4.2
2025-06-30 4.1
2025-07-31 4.2
2025-08-31 4.3

239 rows × 1 columns

Hide code cell content

ld.close_session()