fix: preserve NaNs in cross-sectional ranks
This commit is contained in:
@@ -49,8 +49,10 @@ class MultiFactorStrategy(Strategy):
|
||||
value = stock.rolling(self.value_period).min() / stock
|
||||
|
||||
# --- Cross-sectional ranking (each row ranked across assets) ---
|
||||
mom_rank = momentum.rank(axis=1, pct=True, na_option="bottom")
|
||||
val_rank = value.rank(axis=1, pct=True, na_option="bottom")
|
||||
# na_option="keep" so NaN stocks (pre-IPO / delisted / masked) stay
|
||||
# NaN in the composite score instead of being assigned pct=1.0.
|
||||
mom_rank = momentum.rank(axis=1, pct=True, na_option="keep")
|
||||
val_rank = value.rank(axis=1, pct=True, na_option="keep")
|
||||
scores = mom_rank + val_rank # combined score, higher = better
|
||||
|
||||
# --- Select top_n assets per row ---
|
||||
|
||||
Reference in New Issue
Block a user