gaurv007 commited on
Commit
c607dda
Β·
verified Β·
1 Parent(s): 7e2810c

Upload alpha_factory/deterministic/acceptance_checklist.py with huggingface_hub

Browse files
alpha_factory/deterministic/acceptance_checklist.py ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Acceptance Checklist β€” Layer 7 enforcer.
3
+ Every alpha MUST pass all 14 checks before submission.
4
+ This is the "print and tape to your monitor" checklist, codified.
5
+ """
6
+ from dataclasses import dataclass, field
7
+ from ..schemas import Blueprint, Expression, LintResult
8
+ from ..deterministic.lint import quick_dedup_hash
9
+
10
+
11
+ @dataclass
12
+ class ChecklistResult:
13
+ """Result of running the full acceptance checklist."""
14
+ all_passed: bool = False
15
+ checks: dict = field(default_factory=dict)
16
+ blocking_failures: list = field(default_factory=list)
17
+
18
+ def __str__(self):
19
+ lines = ["═══ ACCEPTANCE CHECKLIST ═══"]
20
+ for name, passed in self.checks.items():
21
+ icon = "βœ“" if passed else "βœ—"
22
+ lines.append(f" [{icon}] {name}")
23
+ if self.blocking_failures:
24
+ lines.append(f"\n BLOCKING: {', '.join(self.blocking_failures)}")
25
+ lines.append(f"\n VERDICT: {'PASS βœ“' if self.all_passed else 'FAIL βœ—'}")
26
+ return "\n".join(lines)
27
+
28
+
29
+ def run_acceptance_checklist(
30
+ blueprint: Blueprint,
31
+ expression: Expression,
32
+ lint_result: LintResult,
33
+ alpha_id: str,
34
+ existing_hashes: set,
35
+ existing_anomaly_tags: list,
36
+ max_corr_to_library: float = 0.0,
37
+ local_sim_sharpe: float = 0.0,
38
+ local_sim_fitness: float = 0.0,
39
+ local_sim_turnover: float = 0.0,
40
+ returns_corr: float = 0.0,
41
+ sign_validated: bool = False,
42
+ ) -> ChecklistResult:
43
+ """
44
+ Run all 14 acceptance checks from Β§3 of the design doc.
45
+ Returns ChecklistResult with pass/fail for each.
46
+ """
47
+ checks = {}
48
+ failures = []
49
+
50
+ # 1. ARCHETYPE β€” maps to proven archetype or cites paper
51
+ archetype_ok = (
52
+ blueprint.archetype in ["value_quality_blend", "intraday_mr_decay", "vol_scaled_shock",
53
+ "pead_revisions", "skew_term", "social_momentum",
54
+ "multi_horizon_mr", "fundamental_yield_composite"]
55
+ or blueprint.academic_anchor is not None
56
+ )
57
+ checks["ARCHETYPE (proven or cited)"] = archetype_ok
58
+ if not archetype_ok:
59
+ failures.append("No proven archetype and no academic anchor")
60
+
61
+ # 2. LINT β€” passes static lint
62
+ checks["LINT (operators, lookahead, units)"] = lint_result.passed
63
+ if not lint_result.passed:
64
+ failures.append(f"Lint failed: {lint_result.errors[:2]}")
65
+
66
+ # 3. DEDUP β€” not already in factor store
67
+ dedup_ok = alpha_id not in existing_hashes
68
+ checks["DEDUP (not in factor store)"] = dedup_ok
69
+ if not dedup_ok:
70
+ failures.append("Duplicate expression")
71
+
72
+ # 4. COVERAGE β€” fields have coverage β‰₯ 0.5 (placeholder β€” need field coverage data)
73
+ checks["COVERAGE (fields β‰₯ 0.5)"] = True # assume pass until we have coverage data
74
+
75
+ # 5. SIGN β€” direction validated
76
+ checks["SIGN (validated by paper or sweep)"] = sign_validated or blueprint.academic_anchor is not None
77
+ if not (sign_validated or blueprint.academic_anchor):
78
+ failures.append("Sign not validated")
79
+
80
+ # 6. LOCAL SIM β€” passes local BRAIN simulation
81
+ local_sim_pass = local_sim_sharpe >= 1.0
82
+ checks["LOCAL SIM (Sharpe β‰₯ 1.0)"] = local_sim_pass
83
+
84
+ # 7. CORRELATION β€” max corr to library < 0.65
85
+ corr_ok = max_corr_to_library < 0.65
86
+ checks["CORRELATION (< 0.65 to library)"] = corr_ok
87
+ if not corr_ok:
88
+ failures.append(f"Max corr {max_corr_to_library:.2f} β‰₯ 0.65")
89
+
90
+ # 8. RETURNS-CORR β€” not a momentum mirror, not noise
91
+ returns_corr_ok = 0.05 <= abs(returns_corr) <= 0.85
92
+ checks["RETURNS-CORR (0.05 ≀ |corr| ≀ 0.85)"] = returns_corr_ok
93
+
94
+ # 9. ANOMALY-TAG β€” novel or under-represented
95
+ tag_count = existing_anomaly_tags.count(blueprint.anomaly_tag.value)
96
+ anomaly_ok = tag_count < 3
97
+ checks["ANOMALY-TAG (< 3 in library)"] = anomaly_ok
98
+ if not anomaly_ok:
99
+ failures.append(f"Anomaly '{blueprint.anomaly_tag.value}' already has {tag_count} alphas")
100
+
101
+ # 10. ACADEMIC ANCHOR β€” at least one cited paper
102
+ checks["ACADEMIC ANCHOR (paper cited)"] = blueprint.academic_anchor is not None
103
+
104
+ # 11. NEUTRALIZED β€” chosen consciously
105
+ checks["NEUTRALIZED (explicit choice)"] = blueprint.neutralization.value != "none"
106
+
107
+ # 12. DECAY β€” applied if noisy
108
+ checks["DECAY (applied if needed)"] = blueprint.decay > 0
109
+
110
+ # 13. NOVELTY CLAIM β€” non-empty, meaningful
111
+ novelty_ok = len(blueprint.novelty_claim) >= 20
112
+ checks["NOVELTY CLAIM (β‰₯ 20 chars)"] = novelty_ok
113
+
114
+ # 14. DECISION TREE β€” kill criterion defined (implicit in pipeline)
115
+ checks["DECISION TREE (kill criterion set)"] = True
116
+
117
+ # Overall verdict
118
+ all_passed = len(failures) == 0 and all(checks.values())
119
+
120
+ return ChecklistResult(
121
+ all_passed=all_passed,
122
+ checks=checks,
123
+ blocking_failures=failures,
124
+ )