quantlab.factor.predefined.membership_mask.MembershipMaskedFactor#

class quantlab.factor.predefined.membership_mask.MembershipMaskedFactor(config)[source]#

Bases: FactorView

The outputs of config.factor, NaN where the symbol is not a member at the bar.

A cell is kept when config.membership.is_member_at is true on the bar’s date; a symbol missing from the membership panel is not a member, and a bar whose date the membership panel does not cover is refused, warm-up bars included: a model reading it from start_date with a warm-up needs the membership from that many bars earlier. A panel none of whose symbols is on the membership store’s axis is refused too, since it would be masked whole. The outputs keep the wrapped factor’s names, so the wrapper replaces the factor in a model’s config without anything else changing.

A model’s feature window over a symbol that joined less than a window ago holds NaN for the bars before it joined, which a live model would know: a small loss of information, not look-ahead.

The store queries are a view’s (see FactorView): every symbol of the wrapped factor is kept, store_path is None, store_uses() reads the wrapped factor’s store, store_range() is the wrapped factor’s, owns_store() is false and build and extend are refused.

Parameters:
configMembershipMaskedFactorConfig

The wrapped factor and the membership dataset.

Examples

With alphas a factor on symbols 2 (always a member) and 4 (a member from 2024-01-22 on):

>>> factor = MembershipMaskedFactor(
...     MembershipMaskedFactorConfig(factor=alphas, membership=membership)
... )
>>> factor.read("2024-01-18", "2024-01-23")["c"].notnull().to_pandas()
symbol        2      4
timestamp
2024-01-18  True  False
2024-01-19  True  False
2024-01-22  True   True
2024-01-23  True   True
config_cls#

The config class from_config rebuilds this factor with.

alias of MembershipMaskedFactorConfig