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 0x7fa3f48a23c0 {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
2024-10-17 232.45 233.34 231.75 235351 231.75 231.0 235.0 232.51805 1 58400 1212 1 72000 54723356.08 <NA> 232.45
2024-10-18 232.76 233.58 231.85 270498 232.36 232.27 233.28 232.67492 2 52100 1368 1 73107 62938100.86 <NA> 232.76
2024-10-21 232.18 233.86 230.63 170396 231.83 228.25 233.15 231.99079 <NA> <NA> 1382 1 72000 39530302.12 <NA> 232.18
2024-10-22 230.44 231.68 229.36 207597 230.8 230.21 234.0 230.39046 2 40000 1277 1 72000 47828369.14 <NA> 230.44
2024-10-23 231.3 232.43 229.8 142508 230.43 230.0 234.0 231.37439 <NA> <NA> 1203 1 72000 32972701.62 <NA> 231.3
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2025-10-08 211.75 212.11 210.25 634701 211.41 210.01 214.9 211.64048 6 206700 2736 1 73410 134328426.24 <NA> 211.75
2025-10-09 210.48 211.59 209.7 292006 211.31 210.0 214.9 210.38067 1 11400 2163 1 72000 61432418.13 <NA> 210.48
2025-10-10 212.03 213.02 209.23 474377 211.39 212.03 214.9 211.7942 <NA> <NA> 3399 1 73357 100470295.76 <NA> 212.03
2025-10-14 217.14 218.44 212.78 679248 213.63 216.88 218.5 217.07122 3 158100 4199 1 72000 147445189.16 <NA> 217.14
2025-10-15 223.78 225.5 221.49 581433 224.37 223.35 224.25 223.74637 <NA> <NA> 4221 1 72000 130093524.5 <NA> 223.78

250 rows × 16 columns

Hide code cell content

ld.close_session()