quantlab.model.predefined.membership_mask.MembershipMaskedPredictor#
- class quantlab.model.predefined.membership_mask.MembershipMaskedPredictor(predictor, membership)[source]#
Bases:
PredictorViewA
Predictorwhose predictions are NaN where the symbol is not an index member.predict_windowasks the wrapped predictor for its predictions and keeps a cell only when the membership panel’sis_memberis true on that bar’s date for that symbol; every other protocol member forwards to the wrapped predictor unchanged (PredictorView). The mask at bar t reads the membership of t’s date and nothing later, so it is information at t. Prices, tradability and delistings are untouched: a security that leaves the index keeps its prices, its prediction turns NaN, and the portfolio rule decides what happens to a holding (TopN sells it at the next rebalance, mean-variance holds it at mu=0).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:
- predictorPredictor
The model or ensemble whose predictions are masked.
- membershipIndexConstituentDataset
The point-in-time membership, with a stored
is_memberpanel on the symbol axis of the predictions (PERMNOs for CRSP stores).
- Attributes:
- predictorPredictor
The wrapped predictor.
- membershipIndexConstituentDataset
The membership dataset.
Examples
With
modela model over CRSP PERMNOs andmembershiptheCrspSP500ConstituentDatasetover the same roster:>>> masked = MembershipMaskedPredictor(model, membership) >>> backtester = USEquityCrossectionSelectStockVectorBt( ... CrossSectionBacktestConfig( ... price_dataset=crsp_index_dataset, # unmasked prices ... model=masked, model_mode="load", checkpoint=checkpoint, ... start_date="2020-01-01", end_date="2024-12-31", ... output_dir="runs", rebalance_periods=5, ... constructor=TopNConstructor(TopNConfig(top_n=50)), ... ) ... ) >>> result = backtester.run() # predictions.zarr is masked too
- config_cls#
The config dataclass the wrapper is serialised and rebuilt with.
alias of
MembershipMaskConfig