quantlab.dataset.bad_prints.BadPrintMaskedDataset#

class quantlab.dataset.bad_prints.BadPrintMaskedDataset(config, **params)[source]#

Bases: MergedDataset

A merged view of datasets whose bad prints have no price.

Parameters:
configBadPrintMaskedDatasetConfig or sequence of BaseDataset

The datasets to merge, in order, or a config holding them and the rule.

**params

With a sequence of datasets, the rule’s fields of BadPrintMaskedDatasetConfig (jump, volume_ratio, lookback, price_variable, volume_variable, masked_variables).

Raises:
ValueError

As MergedDataset, or if jump is not above 1, volume_ratio not positive or lookback below 1.

Examples

sep holds Sharadar SEP prices and daily its market caps; CNYD (permaticker 120127) printed $0.01 on 2009-06-19, between $7.20 and $9.00:

>>> prices = BadPrintMaskedDataset([sep, daily])
>>> panel = prices.panel("2009-06-18", "2009-06-23", symbols=[120127])
>>> panel["close"].values.ravel().tolist()
[7.2, nan, 9.0, 9.0]
>>> MergedDataset([sep, daily]).panel("2009-06-18", "2009-06-23", symbols=[120127])["close"].values.ravel().tolist()
[7.2, 0.01, 9.0, 9.0]
bad_prints(start, end, symbols=None)[source]#

Return which bars from start to end are bad prints.

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

The range, both inclusive.

symbolssequence, optional

Symbol labels to keep; None keeps every one.

Returns:
xr.DataArray

Booleans on (timestamp, symbol).

Examples

>>> flags = prices.bad_prints("2009-06-18", "2009-06-23", symbols=[120127])
>>> flags.values.ravel().tolist()
[False, True, False, False]
config_cls#

The config class used to rebuild this dataset from a saved config.

alias of BadPrintMaskedDatasetConfig

copy()[source]#

Return the view over copies of the inputs, with the same rule.

Examples

>>> other = prices.copy()
>>> other == prices, other.datasets[0] is prices.datasets[0]
(True, False)
panel(start, end, symbols=None, variables=None)[source]#

Return the merged panel from start to end with its bad prints masked.

The bars are read from twice lookback bars before start (or the first bar), so the flags of a bar do not depend on where the window starts. Of a flagged bar, every variable of masked_variables the panel holds is NaN; the others are the inputs’.

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

The range to return, both inclusive.

symbolssequence, optional

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

variablessequence of str, optional

Shared variable names to keep, in the order given; None keeps every one. The rule’s price and volume are read either way.

Returns:
xr.Dataset

The panel on (timestamp, symbol).

Raises:
ValueError, KeyError

As MergedDataset.panel, or a KeyError if no input holds the rule’s price or volume.

Examples

>>> prices.panel("2009-06-18", "2009-06-23", symbols=[120127], variables=["adjClose"])["adjClose"].isnull().values.ravel().tolist()
[False, True, False, False]