fix: unify backtest execution and add forward validation candidates
Share point-in-time signals and a cash-funded order ledger across backtests and trading. Correct eligibility, missing-price fills, quality factors, regime inputs, warmup windows, and cash-injection accounting. Add reproducible registered-strategy comparisons and paired forward candidates with a 20% resize band. Validation: 125 Python tests, 23 web tests, TypeScript/Vite build, 87 strategy causality checks, and real-data target/order/equity parity for 10 strategies.
This commit is contained in:
@@ -46,6 +46,8 @@ from strategies.factor_combo import SIGNAL_REGISTRY
|
||||
class TrendRiderV6(TrendRiderV5):
|
||||
"""Stock-sleeve TrendRider with V5 regime engine."""
|
||||
|
||||
accepts_eligibility = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*args,
|
||||
@@ -98,10 +100,10 @@ class TrendRiderV6(TrendRiderV5):
|
||||
self.leverage_overlay_symbol, *self.risk_off_basket})
|
||||
return [c for c in prices.columns if c not in non_stock]
|
||||
|
||||
def _stock_top_n_weights(self, prices: pd.DataFrame, universe: list[str]) -> pd.DataFrame:
|
||||
def _stock_top_n_weights(self, prices: pd.DataFrame, universe: list[str], eligible=None) -> pd.DataFrame:
|
||||
"""Top-N selection by signal, inv-vol weighted within selection."""
|
||||
stock_panel = prices[universe]
|
||||
sig = self.signal_func(stock_panel)
|
||||
sig = self.signal_func(stock_panel, eligible=eligible)
|
||||
# Top-N by signal rank (highest score = top)
|
||||
rank = sig.rank(axis=1, ascending=False, na_option="bottom")
|
||||
n_valid = sig.notna().sum(axis=1)
|
||||
@@ -154,7 +156,7 @@ class TrendRiderV6(TrendRiderV5):
|
||||
return {best: 1.0}
|
||||
|
||||
# ---- Override generate_signals ----
|
||||
def generate_signals(self, data: pd.DataFrame) -> pd.DataFrame:
|
||||
def generate_signals(self, data: pd.DataFrame, eligible=None) -> pd.DataFrame:
|
||||
if self.signal not in data.columns:
|
||||
raise ValueError(f"Required regime signal {self.signal!r} not in data.")
|
||||
universe = self._resolve_universe(data)
|
||||
@@ -163,7 +165,7 @@ class TrendRiderV6(TrendRiderV5):
|
||||
|
||||
# 1) Build sleeve weights — stock sleeve, anchor sleeve
|
||||
# (defensive sleeve is single-pick, computed per-bar inside the loop)
|
||||
stock_w = self._stock_top_n_weights(data, universe)
|
||||
stock_w = self._stock_top_n_weights(data, universe, eligible)
|
||||
anchor_w = pd.DataFrame(0.0, index=data.index, columns=[self.moderate_anchor])
|
||||
if self.moderate_anchor in data.columns:
|
||||
anchor_w[self.moderate_anchor] = 1.0
|
||||
|
||||
Reference in New Issue
Block a user