Coverage for scripts/v661_model_audit.py: 100%
36 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
1"""V6.6.1's audit of what the models could know, on free cell S: 18 fixed group x horizon looks, each counted in the trial ledger.
3 python scripts/v661_model_audit.py [--out ml/evaluation/v661/model_audit.json]
4"""
6from __future__ import annotations
8import argparse
9import json
10import sys
11from pathlib import Path
13ROOT = Path(__file__).resolve().parents[1]
14sys.path.insert(0, str(ROOT))
16from evaluation.model_audit import FEATURE_GROUPS, HORIZONS, feature_group_ic, fundamental_coverage # noqa: E402
17from evaluation.trial_ledger import append_trial, read_ledger # noqa: E402
18from evaluation.wide_context import equity_cell # noqa: E402
20LEDGER = ROOT / "ml" / "evaluation" / "v660" / "trial_ledger.jsonl"
23def count_looks(path: Path) -> list[str]:
24 """Appends each look once, with no Sharpe: it raises N and leaves the variance unchanged."""
25 held = {entry["trial_id"] for entry in read_ledger(path)}
26 added = []
27 for group in FEATURE_GROUPS:
28 for horizon in HORIZONS:
29 trial = f"audit:{group}:{horizon}"
30 if trial not in held:
31 append_trial(path, trial_id=trial, track="A", window="v660_selection", role="candidate", annualised_sharpe=None, n_obs=0, engine="offline", detail={"cell": "S", "round": "round3_audit"})
32 added.append(trial)
33 return added
36def main(argv: list[str] | None = None) -> int:
37 parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
38 parser.add_argument("--out", default=str(ROOT / "ml" / "evaluation" / "v661" / "model_audit.json"))
39 args = parser.parse_args(argv)
40 base = json.loads((ROOT / "config.json").read_text(encoding="utf-8"))
41 cell = equity_cell(ROOT, base, "S")
42 report = {"cell": "S", "coverage": fundamental_coverage(cell.features, cell.member), "groups": feature_group_ic(cell), "looks_added": count_looks(LEDGER)}
43 out = Path(args.out)
44 out.parent.mkdir(parents=True, exist_ok=True)
45 out.write_text(json.dumps(report, indent=1, default=str), encoding="utf-8", newline="\n")
46 for group, by_horizon in report["groups"].items():
47 print(group, {horizon: None if entry is None else (round(entry["mean_ic"] or 0.0, 4), round(entry["nonoverlap_t"] or 0.0, 2)) for horizon, entry in by_horizon.items()}, flush=True)
48 return 0
51if __name__ == "__main__":
52 raise SystemExit(main())