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 0x7fd3a8fcf8c0 {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-08-29 243.91 245.59 243.05 317871 244.06 243.6 246.35 244.38314 <NA> <NA> 2133 1 73357 77682312.71 <NA> 243.91
2025-09-02 244.88 245.35 242.99 285331 244.35 240.01 245.5 244.65459 4 73900 1706 1 72000 69807539.45 <NA> 244.88
2025-09-03 244.76 246.75 243.54 387446 244.37 240.01 247.5 245.31938 <NA> <NA> 2611 1 72000 95048012.2 <NA> 244.76
2025-09-04 247.18 248.16 245.82 296595 246.35 240.01 248.25 247.21918 1 17600 2091 1 72000 73323974.01 <NA> 247.18
2025-09-05 241.93 248.5 240.06 502564 247.93 241.68 245.0 242.32282 2 119200 3088 1 72000 121782728.18 <NA> 241.93
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2026-08-21 145.39 147.28 144.415 703872 146.32 144.53 145.91 145.71671 8 219800 3396 1 73369 102565909.34 <NA> 145.39
2026-08-24 150.21 151.23 146.25 524461 146.62 149.0 150.95 149.7075 2 72700 3199 1 72000 78515744.64 <NA> 150.21
2026-08-25 144.24 148.65 144.15 533093 147.88 144.0 145.0 145.23738 2 57000 3214 1 72000 77425031.77 <NA> 144.24
2026-08-26 142.14 146.23 141.62 609650 143.08 142.0 142.84 142.82074 1 22000 4195 1 72997 87070667.01 <NA> 142.14
2026-08-27 145.11 149.37 141.38 509645 141.38 145.0 145.48 146.01884 <NA> <NA> 3625 1 72000 74417770.46 <NA> 145.11

250 rows × 16 columns

Hide code cell content

ld.close_session()