quantlab.dataset.massive.placement.TickerPlacement#

class quantlab.dataset.massive.placement.TickerPlacement(ticker_map, *, owner)[source]#

Bases: object

Place rows on permatickers by the Ticker map of their own day, counting what it cannot place.

One instance serves one build of one store: each place (and leave_out) call adds to the rows left out, and write_report writes them all into the store’s sidecar.

Parameters:
ticker_mapTickerMap

The map read.

ownerstr

Named in the report and in log lines.

Examples

With rows holding ticker and available columns:

placement = TickerPlacement(ticker_map, owner="demo")
placement.place(rows, source="splits", day="available").get_column("permaticker")
leave_out(rows, *, source, reason, day, ticker='ticker')[source]#

Count rows a panel leaves out for a reason of its own (no amount, another currency).

Examples

Count the dividends paid in another currency:

placement.leave_out(rows, source="dividends", reason="currency CAD, not USD", day="ex_dividend_date")
left_out()[source]#

Return every row left out so far: source, ticker, date, reason.

Examples

With placement a TickerPlacement that has left rows out:

placement.left_out().columns
# ['source', 'ticker', 'date', 'reason']
place(rows, *, source, day='available', ticker='ticker')[source]#

Return the rows the Ticker map places, each with its permaticker.

Parameters:
rowspl.DataFrame

Rows with a Massive ticker column ticker and a placement day column day (a date or a datetime at midnight). The day must be a trading day: roll a vendor date onto the calendar first (TradingCalendar.place).

sourcestr

Names the rows in the report ("dividends:ex").

daystr, default “available”

The column of the placement day.

tickerstr, default “ticker”

The column of the Massive ticker.

Returns:
pl.DataFrame

The placed rows, with an int64 permaticker column added; the rest are counted in the report.

Examples

A ticker of the map’s day is placed; one the day’s aggregates lack is counted:

placed = placement.place(rows, source="dividends:ex")
placement.left_out()["reason"].to_list()
# ["the ticker is not in Massive's day aggregates that day"]
write_report(store_path)[source]#

Write the rows left out into <store_path>.unplaced.json, or remove a stale report.

The report is {"owner", "rows", "unplaced": [{"source", "ticker", "first_date", "last_date", "rows", "reason"}, ...]}, one entry per source, ticker and reason, written atomically. With nothing left out an existing report is deleted, so its presence means rows are missing from the store.

Returns:
Path or None

The report written, or None when nothing was left out.

Examples

With placement a TickerPlacement that has left rows out:

placement.write_report("/data/market/massive/massive_dividends_1d/massive_dividends_1d.zarr").name
# 'massive_dividends_1d.zarr.unplaced.json'