How do I request data with the LSEG Data Library?

Request daily prices and market caps from LSEG Workspace, compare the observation date of each field, and keep a market cap only on the day it was observed.

After this lesson, you can ask LSEG Workspace for two stocks’ daily closes and market caps and spot a market cap carried over from an earlier day.

How do I request the fields from Workspace?

ld.get_data(universe=..., fields=..., parameters=...) returns the requested fields for each instrument, one row per instrument and date, and asking for each field’s date, such as TR.CompanyMarketCap.date, shows the day each value describes. ld.get_history returns a time series of a field, and ld.discovery.search finds an instrument’s RIC, LSEG’s code for a quoted instrument, such as MSFT.O for Microsoft on Nasdaq.

The lseg-data package needs Workspace running and signed in on the same computer and an account with access to the fields. Scale=6 requests the market cap in millions, SDate and EDate bound the period, Frq="D" asks for daily rows and Curn="USD" for US dollars. The two date fields can both be named Date, so the box names the columns in request order. finally closes the session even when a request fails. The LSEG data guide links to full examples.

The following box, which does not run on this page, finds Microsoft’s RIC and requests both stocks’ fields.

import lseg.data as ld

ld.open_session()
try:
    matches = ld.discovery.search(view=ld.discovery.Views.EQUITY_QUOTES, query="Microsoft", select="RIC,DocumentTitle", top=3)
    daily = ld.get_data(universe=["MSFT.O", "IBM.N"], fields=["TR.PriceClose.date", "TR.PriceClose", "TR.CompanyMarketCap.date", "TR.CompanyMarketCap(Scale=6)"], parameters={"SDate": "2026-03-02", "EDate": "2026-03-03", "Frq": "D", "Curn": "USD"})
    daily.columns = ["Instrument", "Date", "Price Close", "Cap Date", "Company Market Cap"]
    history = ld.get_history(universe=["MSFT.O", "IBM.N"], fields=["TR.PriceClose"], start="2026-03-02", end="2026-03-03", interval="daily")
finally:
    ld.close_session()

How do I keep a market cap only on its own day?

Comparing each row’s price date with its cap date shows which caps describe another day, and .where(daily["Date"] == daily["Cap Date"]) keeps a cap only when the two dates agree. In the made-up answer, AAA’s 3 March row carries the cap of 2 March, 100 million dollars, so its same-day cap is missing.

The made-up answer has the columns of the request for two made-up stocks, AAA and BBB, with closes in dollars per share and caps in millions of dollars. BBB’s 3 March cap is missing although the row has a cap date. A carried-over cap is fine for some uses, but a calculation that pairs a day’s price with that day’s cap must leave it out.

The following box builds the answer and adds the same-day caps.

import pandas as pd

daily = pd.DataFrame({
    "Instrument": ["AAA", "BBB", "AAA", "BBB"],
    "Date": pd.to_datetime(["2026-03-02", "2026-03-02", "2026-03-03", "2026-03-03"]),
    "Price Close": [50, 20, 51, 21],
    "Cap Date": pd.to_datetime(["2026-03-02", "2026-03-02", "2026-03-02", "2026-03-03"]),
    "Company Market Cap": [100, 80, 100, None],
})
daily["same_day_cap"] = daily["Company Market Cap"].where(daily["Date"] == daily["Cap Date"])
print(daily.to_string())
  Instrument       Date  Price Close   Cap Date  Company Market Cap  same_day_cap
0        AAA 2026-03-02           50 2026-03-02               100.0         100.0
1        BBB 2026-03-02           20 2026-03-02                80.0          80.0
2        AAA 2026-03-03           51 2026-03-02               100.0           NaN
3        BBB 2026-03-03           21 2026-03-03                 NaN           NaN

Your turn

Put the same-day caps into a table with the dates down the rows and one column per stock. You should see 100 and 80 on 2 March and two missing caps on 3 March.

.pivot() puts each stock in its own column, as in the lesson on pivot and melt.

print(daily.pivot(index="Date", columns="Instrument", values="same_day_cap"))
Instrument    AAA   BBB
Date                   
2026-03-02  100.0  80.0
2026-03-03    NaN   NaN