Coverage for scripts/v660_sanity.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"""Is the wide scoring path able to see an edge at all? A result of "no edge" is worthless if the path is broken, so before it's believed:
3an oracle signal (the label itself, which reads the future) must score hugely, its reversal hugely badly, and a random signal about zero less costs.
4These are plumbing: they enter no ledger, no PBO and no count of trials, and read only cell S.
6 python scripts/v660_sanity.py
7"""
9from __future__ import annotations
11import json
12import sys
13from pathlib import Path
15import numpy as np
16import pandas as pd
18ROOT = Path(__file__).resolve().parents[1]
19sys.path.insert(0, str(ROOT))
20sys.path.insert(0, str(ROOT / "scripts"))
22from v660_trials import W # noqa: E402
24from evaluation.premia_research import score_sleeve # noqa: E402
25from evaluation.wide_context import equity_cell, signal_ic_t # noqa: E402
26from portfolio.premia_signals import SleeveSpec # noqa: E402
28OUT = ROOT / "ml" / "evaluation" / "v660" / "sanity_wide_path.json"
31def main() -> int:
32 base = json.loads((ROOT / "config.json").read_text(encoding="utf-8"))
33 cell = equity_cell(ROOT, base, "S", with_info=False)
34 template = W[0]
35 member = cell.member
36 label = cell.label.where(member)
37 rng = np.random.default_rng(66)
38 random_table = pd.DataFrame(rng.normal(size=label.shape), index=label.index, columns=label.columns).where(member)
39 tables = {"oracle": label, "reversed_oracle": -label, "random": random_table}
40 report = {}
41 for name, table in tables.items():
42 cell.context.panel.extras[name] = table
43 spec = SleeveSpec(name, "sanity", template.kind, template.family, template.universe, template.rebalance_every, {"table": name, "top_k": template.params["top_k"]})
44 score = score_sleeve(spec, cell.context, start=cell.cell.start, split=cell.cell.split, end=cell.cell.end, signal=table)
45 score.pop("daily")
46 ic = signal_ic_t(table, cell.label, start=cell.cell.start, end=cell.cell.end)
47 report[name] = {"sharpe": score["sharpe"], "first_half": score["sharpe_first_half"], "second_half": score["sharpe_second_half"], "mean_gross": score["mean_gross"], "turnover": score["turnover"], "mean_ic": ic["mean_ic"]}
48 print(name, report[name], flush=True)
49 OUT.write_text(json.dumps(report, indent=1), encoding="utf-8", newline="\n")
50 return 0
53if __name__ == "__main__":
54 raise SystemExit(main())