quantlab.label.predefined.membership_mask.MembershipMaskedLabel#
- class quantlab.label.predefined.membership_mask.MembershipMaskedLabel(label, membership)[source]#
Bases:
ComponentA label that is NaN where the symbol is not an index member at t.
readandcomputereturn the wrapped label’s panel with a cell kept only when the membership panel’sis_memberis true on that bar’s date for that symbol. The mask at bar t reads the membership of t’s date and nothing later, so a symbol that leaves the index inside the label’s horizon keeps its return at t, and a symbol that is not a member at t has no label whatever its later membership. Every other label method forwards to the wrapped label unchanged; the wrapper owns no store.A symbol missing from the membership panel is not a member. A bar whose date the membership panel does not cover (before its first or after its last day) is refused, because unknown membership is not “not a member”.
- Parameters:
- labelForward
The label to mask, such as
quantlab.label.predefined.fret.Returncomputed on the index’s unmasked prices.- membershipIndexConstituentDataset
The point-in-time membership, with a stored
is_memberpanel on the label’s symbol axis (PERMNOs for CRSP stores).
- Attributes:
- labelForward
The wrapped label.
- membershipIndexConstituentDataset
The membership dataset.
Examples
With
pricesaCrspStockDatasetover the S&P 500 roster’s unmasked prices andmembershiptheCrspSP500ConstituentDatasetover the same roster:>>> ret = Return(FactorConfig(dataset=prices, warmup_bars=0, data_columns=("adjOpen",), ... kwargs={"n_forward_periods": 20})) >>> label = MembershipMaskedLabel(ret, membership) >>> label.get_factor_names(), label.lookahead_bars(), label.span_bars() (('ret_20',), 21, 20) >>> model = XGBoostRegressor(ModelConfig(factors=[alpha158], labels=[label], ...))
- build(start, end)[source]#
Build the wrapped label’s store; returns the wrapper.
The membership store is not built here; save it beforehand.
Examples
>>> label.build("2024-01-01", "2024-02-29") is label True
- property class_name#
Bare class name, used in log and error messages.
Examples
>>> label.class_name 'MembershipMaskedLabel'
- compute(start, end)[source]#
Compute the wrapped label from
starttoendand mask it.- Parameters:
- start, endstr, datetime.date or pd.Timestamp
The range to return; see
Forward.compute.
- Returns:
- xr.Dataset
The masked label panel on
(timestamp, symbol), in memory.
Examples
>>> label.compute("2024-02-01", "2024-02-10").equals( ... membership.mask(ret.compute("2024-02-01", "2024-02-10"))) True
- property config#
The wrapped label and the membership dataset;
get_config()serialises it.Examples
>>> sorted(label.get_config()) ['label', 'membership', 'name']
- config_cls#
The config dataclass the wrapper is serialised and rebuilt with.
alias of
MembershipMaskedLabelConfig
- delay_bars()[source]#
The wrapped label’s delay, which a model reports as its
label_delays.Examples
>>> label.delay_bars() == ret.delay_bars() True
- extend(end)[source]#
Extend the wrapped label’s store to
end; returns the wrapper.Examples
>>> label.extend("2024-03-29") is label True
- classmethod from_config(config, run_dir=None)[source]#
Rebuild the wrapper, its label and its membership dataset from
get_config().Both are rebuilt by the component rule, with
run_dirpassed down.Examples
>>> MembershipMaskedLabel.from_config(label.get_config()) == label True
- get_factor_names()[source]#
The wrapped label’s variable names.
Examples
>>> label.get_factor_names() == ret.get_factor_names() True
- property kind#
The wrapped label’s
kind; masking changes what is measured nowhere.Examples
>>> label.kind 'return'
- lookahead_bars()[source]#
The wrapped label’s lookahead; masking reads no later bar.
Examples
>>> label.lookahead_bars() == ret.lookahead_bars() True
- read(start, end)[source]#
Return the wrapped label’s stored panel from
starttoend, masked.- Parameters:
- start, endstr, datetime.date or pd.Timestamp
The range to return; see
Forward.read.
- Returns:
- xr.Dataset
The masked label panel on
(timestamp, symbol).
Examples
>>> label.build("2024-01-01", "2024-02-29") >>> label.read("2024-02-01", "2024-02-10").equals( ... membership.mask(ret.read("2024-02-01", "2024-02-10"))) True