Add full-period S/R production comparison

This commit is contained in:
2026-07-13 09:37:39 +02:00
parent 3280ed71f7
commit e6dc74df6f
14 changed files with 119 additions and 2575176 deletions
+54 -13
View File
@@ -42,6 +42,10 @@ RANGE_RESIDUAL_ARMS = (
"rewrite_range504_structural_legacy_primary",
"rewrite_range504_structural_primary2",
)
FULL_PERIOD_ARMS = (
"production_control",
"rewrite_range504_structural_legacy_primary",
)
def _add_common(parser: argparse.ArgumentParser) -> None:
@@ -91,6 +95,11 @@ def _args() -> argparse.Namespace:
default=None,
help="Run one residual target-geometry arm without repeating the pair.",
)
full = commands.add_parser(
"full",
help="Run current production and the frozen candidate over the full snapshot.",
)
_add_common(full)
validate = commands.add_parser(
"validate",
help="Run production control and one locked arm from 2024-07-01.",
@@ -105,23 +114,27 @@ def _run_arm(
snapshot: str,
workers: int,
*,
entry_flag: str,
entry_date: str,
entry_flag: str | None = None,
entry_date: str | None = None,
output: Path,
) -> None:
print(f"Running S/R arm: {arm}", flush=True)
command = [
sys.executable,
str(RUNNER),
snapshot,
"--workers", str(workers),
"--allow-spawn",
"--sr-variant", arm,
"--sr-audit",
"--out", str(output),
]
if entry_flag is not None and entry_date is not None:
command.extend((entry_flag, entry_date))
elif entry_flag is not None or entry_date is not None:
raise ValueError("entry_flag and entry_date must be provided together")
subprocess.run(
[
sys.executable,
str(RUNNER),
snapshot,
"--workers", str(workers),
"--allow-spawn",
"--sr-variant", arm,
entry_flag, entry_date,
"--sr-audit",
"--out", str(output),
],
command,
cwd=ROOT,
check=True,
)
@@ -171,6 +184,32 @@ def _validate(args: argparse.Namespace) -> None:
)
def _full(args: argparse.Namespace) -> None:
reports: dict[str, Path] = {}
for arm in FULL_PERIOD_ARMS:
output = ROOT / "reports" / f"backtest-sr-full-{arm}.json"
reports[arm] = output
_run_arm(
arm,
args.snapshot,
args.workers,
output=output,
)
subprocess.run(
[
sys.executable,
str(COMPARE),
str(reports["production_control"]),
str(reports["rewrite_range504_structural_legacy_primary"]),
"--out-csv", str(ROOT / "reports" / "sr-full-production-vs-candidate-cohorts.csv"),
"--out-json", str(ROOT / "reports" / "sr-full-production-vs-candidate-comparison.json"),
],
cwd=ROOT,
check=True,
)
print("Full-period production comparison complete.")
def main() -> None:
args = _args()
if args.command == "train":
@@ -184,6 +223,8 @@ def main() -> None:
elif args.command == "residual":
arms = (args.only_arm,) if args.only_arm else RANGE_RESIDUAL_ARMS
_train(args, arms, "backtest-sr-range-residual-train")
elif args.command == "full":
_full(args)
else:
_validate(args)