quantlab.model.predefined.membership_mask#

Mask a predictor’s predictions with an index’s point-in-time membership.

An index such as the S&P 500 is a universe: it says which securities a strategy may enter at bar t. That is a decision input, so it belongs on the predictions, never on the prices. A security that leaves the index is still quoted and can still be sold; masking its prices instead would make it untradable on its first non-member bar and settle it like a delisting at its last member close, a sale that never happens live.

MembershipMaskedPredictor wraps any Predictor and sets its predictions to NaN wherever the symbol is not an index member at that bar. It changes nothing else, so it drops into BacktestConfig.model in place of the model it wraps, and the backtester’s predictions.zarr holds the masked panel.

Classes

MembershipMaskConfig

What a MembershipMaskedPredictor is rebuilt from.

MembershipMaskedPredictor

A Predictor whose predictions are NaN where the symbol is not an index member.