quantlab.model.collected_panel.CollectedPanel#

class quantlab.model.collected_panel.CollectedPanel(data, record=None, source=None)[source]#

Bases: object

A model’s collected panel: the data sorted on both axes, its read record, its arrays.

Parameters:
dataxr.Dataset

The factors and labels on (timestamp, symbol); sorted on both axes here when it is not.

recorddict, optional

What the reads recorded, keyed by component path within the model that collected (BaseModel.training_record).

sourcedict, optional

What the panel was read for: the factor and label configs and the dates (BaseModel.use_panel compares it).

Examples

>>> panel = model.collect().collected_panel
>>> panel.data.sizes
Frozen({'timestamp': 40, 'symbol': 3})
>>> panel.array(["f_a"])[0] is panel.array(["f_a"])[0]
True
array(names, dtype=None)[source]#

Return names as one [T, S, len(names)] array, with its timestamps and symbols.

Built by to_array once per variable list and resolved type, then kept with the panel: every caller gets the same array, and none may write into it.

Parameters:
nameslist[str]

The variables, in order.

dtypenumpy dtype, optional

The array’s type; by default the variables’ common type.

Returns:
tuple

The array, the panel’s timestamps and its symbols.

Examples

>>> x, timestamps, symbols = panel.array(["f_a", "f_b"], np.float32)
>>> x.shape, len(timestamps), len(symbols)
((40, 3, 2), 40, 3)
classmethod assemble(features, labels, source=None, feature_names=None)[source]#

Join a model’s features and labels into one panel on the features’ bars and symbols.

The features decide the axes: the labels are reindexed onto them, so a label’s symbol or bar without features is dropped (nothing can be fitted or predicted on it) and a feature’s warm-up bar has NaN labels. The features are held once: they are stacked into one [T, S, F] FEATURE_DTYPE array in feature_names order, the array array(feature_names, FEATURE_DTYPE) returns, and the panel’s feature variables are views of it.

Parameters:
featuresxr.Dataset

The factor panels on (timestamp, symbol).

labelsxr.Dataset

The label panels on (timestamp, symbol).

sourcedict, optional

What the panel was read for (see the class).

feature_nameslist[str], optional

The feature variables in the order the model reads them; the order of features’ variables when not given.

Returns:
CollectedPanel

The panel, with an empty record.

Raises:
ValueError

If no label symbol is on the features’ symbol axis (an integer permaticker against a text one), which would leave every label NaN.

Examples

With features on symbols A and B and labels on A, B and C:

>>> CollectedPanel.assemble(features, labels).data["symbol"].values.tolist()
['A', 'B']
property data#

The panel on (timestamp, symbol), both axes increasing.

Examples

>>> panel.data.indexes["symbol"].is_monotonic_increasing
True
property record#

What the reads recorded, keyed by component path (a copy).

Examples

>>> sorted(panel.record)
['factors.0.dataset', 'labels.0.factor.dataset']
property source#

What the panel was read for: factor and label configs and dates.

Examples

>>> sorted(panel.source)
['end_date', 'factors', 'labels', 'start_date']
with_record(record)[source]#

Return this panel with record as its read record, its data and arrays shared.

Parameters:
recorddict

What the reads recorded, keyed by component path.

Returns:
CollectedPanel

A new panel on the same data, source and built arrays.

Examples

>>> panel.with_record({"factors.0.dataset": "r"}).record
{'factors.0.dataset': 'r'}