quantlab.dataset.massive.permaticker_bars.PermatickerDataset#

class quantlab.dataset.massive.permaticker_bars.PermatickerDataset(config, ticker_map=None)[source]#

Bases: MarketDataset

A store on the Massive ticker axis read on the permaticker axis; see the module docstring.

A subclass names the config field holding the store’s dataset (SOURCE_FIELD), the class it must be (SOURCE_CLS) and how the store tells its last day (stored_through).

Parameters:
configFrozenConfig or MarketDataset

The config, or the store’s dataset with ticker_map beside it.

ticker_mapTickerMap, optional

The Ticker map, when config is the store’s dataset.

Raises:
ValueError

If the config’s store dataset is not a SOURCE_CLS reading the store’s own bars, or its ticker_map not a TickerMap.

Examples

With trade_bars the Trade bar store and ticker_map the Ticker map:

bars = PermatickerTradeBarDataset(trade_bars, ticker_map)
bars.ticker_bars is trade_bars
# True
SOURCE_CLS#

The class that dataset must be.

SOURCE_FIELD#

The config field holding the dataset on the Massive ticker axis.

columns(start, end)[source]#

Return the ticker each permaticker’s column holds on each mapped day of start..``end``.

Where two stored tickers map to one permaticker on a day, the busier one holds the column (the rule panel applies), so an event of the other ticker is not the column’s.

Parameters:
start, endstr, datetime.date or pd.Timestamp

The days, both inclusive.

Returns:
pl.DataFrame

date, ticker and permaticker, by date and permaticker.

Examples

With bars a permaticker view built beforehand (PermatickerTradeBarDataset):

bars.columns("2024-11-29", "2024-11-29").filter(pl.col("permaticker") == 101)["ticker"].to_list()
# ['AAA']
copy()[source]#

Return a view over a copy of the store’s dataset and the same map’s config.

Examples

With bars a permaticker view built beforehand (PermatickerTradeBarDataset):

other = bars.copy()
other == bars, other.ticker_bars is bars.ticker_bars
# (True, False)
inputs()[source]#

Return the store’s dataset, the one dataset panel reads (the Ticker map is not a dataset).

Examples

With trade_bars the Trade bar store and ticker_map the Ticker map:

PermatickerTradeBarDataset(trade_bars, ticker_map).inputs() == (trade_bars,)
# True
no_bar_fills()[source]#

Return the values of a column without a bar: zero volumes and counts; prices stay NaN.

Examples

With day_bars the Day aggregate store and ticker_map the Ticker map:

PermatickerDayBarDataset(day_bars, ticker_map).no_bar_fills()
# {'volume': 0.0, 'n_trades': 0.0}
panel(start, end, symbols=None, variables=None)[source]#

Return the store’s bars from start to end on the permaticker axis.

Parameters:
start, endstr, datetime.date or pd.Timestamp

The range to return, both inclusive.

symbolssequence of int, optional

Permatickers to return, in the order given; None returns every permaticker the map names in the range.

variablessequence of str, optional

Variables to keep, in the order given; None keeps every one.

Returns:
xr.Dataset

The panel on (timestamp, symbol), symbol the int64 permaticker.

Examples

With bars a permaticker view built beforehand (PermatickerTradeBarDataset):

bars.panel("2024-11-27", "2024-11-30", symbols=[303], variables=["close"])["symbol"].values.tolist()
# [303]
resample(freq, how=None)[source]#

Return this view on freq bars, the mapped bars aggregated per session.

Parameters:
freqstr

A ResampleFrequency token, coarser than the store’s bars.

howdict[str, str], optional

{variable: method}; None uses the store’s defaults.

Returns:
PermatickerDataset

A new view.

Examples

With bars a permaticker view built beforehand (PermatickerTradeBarDataset):

bars.resample("1h").panel("2024-11-27", "2024-11-30").sizes["timestamp"]
# 11
resample_labels(timestamps, freq)[source]#

Return the bars the store’s dataset cuts timestamps into.

stored_symbols()[source]#

Return every permaticker the map names for a stored ticker, sorted.

Examples

With bars a permaticker view built beforehand (PermatickerTradeBarDataset):

bars.stored_symbols()
# [101, 202, 303, 404, 505]
stored_through()[source]#

Return the last day the store on the Massive ticker holds, None without one.

Examples

With day_bars the Day aggregate store and ticker_map the Ticker map:

PermatickerDayBarDataset(day_bars, ticker_map).stored_through()
# datetime.date(2024, 11, 29)
property ticker_bars#

The dataset on the Massive ticker axis the view maps.

Examples

With day_bars the Day aggregate store and ticker_map the Ticker map:

PermatickerDayBarDataset(day_bars, ticker_map).ticker_bars is day_bars
# True
property ticker_map#

The Ticker map.

Examples

With trade_bars the Trade bar store and ticker_map the Ticker map:

PermatickerTradeBarDataset(trade_bars, ticker_map).ticker_map is ticker_map
# True
unplaced(start, end)[source]#

Return {day: count} of the stored tickers the map cannot place, per mapped day.

A ticker is counted on a day when the map has a row for it (it had a bar in Massive’s day aggregates) and no permaticker; its bars are in no column of the view that day. Days without such a ticker are left out.

Parameters:
start, endstr, datetime.date or pd.Timestamp

The days to count, both inclusive.

Examples

With bars a permaticker view built beforehand (PermatickerTradeBarDataset):

bars.unplaced("2024-11-27", "2024-11-29")   # ZZZ, a test symbol
# {datetime.date(2024, 11, 27): 1, datetime.date(2024, 11, 29): 1}