Coverage for scripts/v660_rescore_v650.py: 100%

38 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-22 12:55 +0000

1"""V6.5.0's sleeves rescored on what V6.6.0 found wrong with their Sharpes: excess returns, and sessions at 252 where a panel has no weekend rows. 

2 

3Report only, on the V6.5.0 selection windows, with each sleeve's frozen spec. R-EDGE1 stays closed and nothing is reinstalled by this. 

4 

5 python scripts/v660_rescore_v650.py [--only t3_trend_blend ...] 

6""" 

7 

8from __future__ import annotations 

9 

10import argparse 

11import json 

12import sys 

13from pathlib import Path 

14 

15ROOT = Path(__file__).resolve().parents[1] 

16sys.path.insert(0, str(ROOT)) 

17sys.path.insert(0, str(ROOT / "scripts")) 

18 

19from v650_research import ALL_SPECS, load_context, read_json, window_of # noqa: E402 

20 

21from evaluation.premia_research import passes_sharpe_clauses, score_sleeve # noqa: E402 

22 

23V650 = ROOT / "ml" / "evaluation" / "v650" 

24OUT = ROOT / "ml" / "evaluation" / "v660" / "v650_rescore.json" 

25 

26 

27def main() -> int: 

28 parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) 

29 parser.add_argument("--only", nargs="*", default=None) 

30 args = parser.parse_args() 

31 rules = json.loads((V650 / "rules.json").read_text(encoding="utf-8")) 

32 frozen = read_json(V650 / "selection_scores.json", {}) 

33 context = load_context() 

34 report = read_json(OUT, {}) 

35 for spec in ALL_SPECS: 

36 if (args.only and spec.id not in args.only) or spec.id in report: 

37 continue 

38 table = spec.params.get("table") 

39 if table is not None and table not in context.panel.extras: 

40 continue 

41 start, split, end = window_of(spec, rules) 

42 score = score_sleeve(spec, context, start=start, split=split, end=end) 

43 score.pop("daily", None) 

44 old = frozen.get(spec.id) or {} 

45 report[spec.id] = { 

46 "frozen": {key: old.get(key) for key in ("sharpe", "sharpe_first_half", "sharpe_second_half")}, 

47 "rescored": {key: score.get(key) for key in ("sharpe", "sharpe_first_half", "sharpe_second_half")}, 

48 "frozen_passed_sharpe_clauses": passes_sharpe_clauses(old) if old else None, 

49 "rescored_passes_sharpe_clauses": passes_sharpe_clauses(score), 

50 } 

51 OUT.write_text(json.dumps(report, indent=1), encoding="utf-8", newline="\n") 

52 print(spec.id, report[spec.id]["frozen"]["sharpe"], "->", report[spec.id]["rescored"]["sharpe"], flush=True) 

53 changed = {name: row for name, row in report.items() if row["frozen_passed_sharpe_clauses"] != row["rescored_passes_sharpe_clauses"]} 

54 print(f"{len(report)} rescored, {len(changed)} changed their Sharpe clauses: {sorted(changed)}") 

55 return 0 

56 

57 

58if __name__ == "__main__": 

59 raise SystemExit(main())