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:
@@ -155,12 +155,11 @@ class BacktestUniverseTests(unittest.TestCase):
|
||||
panel = pd.DataFrame(1.0, index=idx, columns=["AAA", "BBB", "SPY", "TQQQ"])
|
||||
fake_universe = {"us": {"fetch": lambda: ["AAA"], "benchmark": "SPY",
|
||||
"benchmark_label": "SPY"}}
|
||||
members = pd.DataFrame(True, index=idx, columns=["AAA", "BBB"])
|
||||
with mock.patch.object(backtest_runner, "UNIVERSES", fake_universe), \
|
||||
mock.patch.object(backtest_runner.uh, "pit_tickers_ever", lambda m, since=None: ["AAA", "BBB"]), \
|
||||
mock.patch.object(backtest_runner.uh, "mask_prices_pit", lambda p, m: p), \
|
||||
mock.patch.object(backtest_runner.data_manager, "update",
|
||||
lambda m, t, fields=None: {f: panel for f in fields}):
|
||||
data = backtest_runner.load_stock_panels("us", ["momentum"], None)
|
||||
mock.patch.object(backtest_runner.uh, "pit_membership", lambda m, days: members.reindex(days).fillna(False)), \
|
||||
mock.patch.object(backtest_runner, "_panels", lambda *a: {"close": panel, "open": panel}):
|
||||
data = backtest_runner.load_stock_panels("us", ["momentum"], None, refresh=False)
|
||||
self.assertEqual(data["stocks"], ["AAA", "BBB"])
|
||||
|
||||
|
||||
@@ -180,15 +179,13 @@ class MembershipTests(unittest.TestCase):
|
||||
bars["open"]["S00"] = bars["close"]["S00"]
|
||||
days = bars["close"].index[-5:]
|
||||
others = [c for c in bars["close"].columns if c != "S00"]
|
||||
members = pd.DataFrame(True, index=days[:-1], columns=bars["close"].columns)
|
||||
members["S00"] = False # joins the index on the last day
|
||||
with mock.patch.object(trader, "index_members", lambda m, d: members.loc[d]):
|
||||
runs = trader.session_universes("us", "momentum", others + ["S00"], days)
|
||||
members = pd.DataFrame(True, index=bars["close"].index, columns=bars["close"].columns)
|
||||
members.loc[members.index < days[-1], "S00"] = False
|
||||
with mock.patch.object(trader, "index_members", lambda m, d: members.reindex(d)):
|
||||
weights = trader.session_signals("us", "momentum", others + ["S00"], days,
|
||||
bars["close"], bars["open"])
|
||||
self.assertEqual([len(r) for _, r in runs], [4, 1])
|
||||
self.assertNotIn("S00", runs[0][0])
|
||||
self.assertTrue((weights.loc[days[:-1], "S00"] == 0).all())
|
||||
# The historical observations were public before index admission.
|
||||
self.assertGreater(weights.loc[days[-1], "S00"], 0)
|
||||
|
||||
def test_changes_table_with_two_level_headers_is_found(self):
|
||||
|
||||
Reference in New Issue
Block a user