quantlab.dataset.sharadar.point_in_time.as_of#

quantlab.dataset.sharadar.point_in_time.as_of(rows, days, symbols, spec)[source]#

Return the point-in-time panel: per day and symbol, the latest row available by then.

A cell shows the symbol’s row with the latest available on or before the day; nothing before its first one. When spec.stale_after_days is set, a cell whose row was released (spec.stamp) more than that many days before the day shows nothing.

Parameters:
rowspl.DataFrame

symbol, available (ns datetime), spec.stamp when set and every variable; at most one row per (symbol, available), sorted by available.

dayspl.Series

The panel’s trading days.

symbolslist of int

The panel’s symbols, in axis order.

specReleaseSpec

The variables and the staleness rule.

Examples

A row released on 2024-01-02 and stale after 3 days:

>>> import polars as pl
>>> days = pl.Series("timestamp", ["2024-01-02", "2024-01-03", "2024-01-08"]).str.to_datetime(time_unit="ns")
>>> rows = pl.DataFrame({"symbol": [101], "available": days[:1], "release_date": days[:1], "value": [5.0]})
>>> spec = ReleaseSpec(variables={"value": {}}, stale_after_days=3)
>>> as_of(rows, days, [101], spec)["value"].values.ravel().tolist()
[5.0, 5.0, nan]