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 0x7f4cd0a8f8c0 {name='rdp'}>

You can use the LSEG Data Library for Python to retrieve the stock prices 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 closing price for the Thomson Reuters stock for the last 365 calendar days:

from datetime import timedelta

ld.get_history(
    "TRI.TO",
    # Note that this number is negative because it's in the past
    start=timedelta(days=-365),
    # `end` is set to zero to draw the latest numbers
    end=timedelta(days=0),
)
TRI.TO TRDPRC_1 HIGH_1 LOW_1 ACVOL_UNS OPEN_PRC BID ASK VWAP BLKCOUNT BLKVOLUM NUM_MOVES TRD_STATUS SALTIM TRNOVR_UNS NAVALUE ALT_CLOSE
Date
2025-07-21 278.31 287.87 278.31 404009 287.87 276.0 282.0 280.54486 <NA> <NA> 3301 1 72989 113342648.18 <NA> 278.31
2025-07-22 275.61 279.45 275.6 296850 278.15 275.02 277.65 276.39519 1 18900 2080 1 72000 82047912.98 <NA> 275.61
2025-07-23 276.5 278.45 275.59 280707 275.59 276.5 276.62 276.46909 1 12100 2012 1 72915 77606808.02 <NA> 276.5
2025-07-24 280.31 280.5 276.5 252598 277.4 275.02 280.5 279.55526 <NA> <NA> 2105 1 72914 70615100.55 <NA> 280.31
2025-07-25 278.86 282.73 278.52 372004 280.31 275.7 281.0 279.86709 <NA> <NA> 3181 1 73375 104111677.66 <NA> 278.86
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2026-07-13 133.22 133.5 128.66 736567 128.94 131.0 133.68 132.23365 <NA> <NA> 4926 1 72000 97398943.25 <NA> 133.22
2026-07-14 129.0 131.77 125.71 886370 128.99 128.45 131.55 129.54592 1 10000 6037 1 72000 114825621.33 <NA> 129.0
2026-07-15 133.87 138.69 129.7 1005237 129.71 132.0 135.0 134.81591 <NA> <NA> 7179 1 72000 135521942.09 <NA> 133.87
2026-07-16 138.73 141.99 135.97 811816 135.97 136.8 141.65 138.96599 1 108100 4964 1 72000 112814810.24 <NA> 138.73
2026-07-17 134.68 140.87 134.14 761248 139.74 134.5 136.0 136.08445 4 71500 4705 1 72000 103594018.53 <NA> 134.68

250 rows × 16 columns

Hide code cell content

ld.close_session()