Upload alpha_factory/deterministic/acceptance_checklist.py with huggingface_hub
Browse files
alpha_factory/deterministic/acceptance_checklist.py
CHANGED
|
@@ -1,16 +1,25 @@
|
|
| 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)
|
|
@@ -40,85 +49,82 @@ def run_acceptance_checklist(
|
|
| 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
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 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
|
| 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
|
| 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
|
| 73 |
-
checks["COVERAGE (fields β₯ 0.5)"] = True
|
| 74 |
|
| 75 |
-
# 5. SIGN
|
| 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
|
| 81 |
-
local_sim_pass = local_sim_sharpe >=
|
| 82 |
-
checks["LOCAL SIM (Sharpe β₯
|
| 83 |
|
| 84 |
-
# 7. CORRELATION
|
| 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
|
| 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
|
| 95 |
-
|
|
|
|
| 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 '{
|
| 100 |
|
| 101 |
-
# 10. ACADEMIC ANCHOR
|
| 102 |
checks["ACADEMIC ANCHOR (paper cited)"] = blueprint.academic_anchor is not None
|
| 103 |
|
| 104 |
-
# 11. NEUTRALIZED
|
| 105 |
-
|
|
|
|
| 106 |
|
| 107 |
-
# 12. DECAY
|
| 108 |
checks["DECAY (applied if needed)"] = blueprint.decay > 0
|
| 109 |
|
| 110 |
-
# 13. NOVELTY CLAIM
|
| 111 |
novelty_ok = len(blueprint.novelty_claim) >= 20
|
| 112 |
checks["NOVELTY CLAIM (β₯ 20 chars)"] = novelty_ok
|
| 113 |
|
| 114 |
-
# 14. DECISION TREE
|
| 115 |
checks["DECISION TREE (kill criterion set)"] = True
|
| 116 |
|
| 117 |
-
|
| 118 |
-
all_passed =
|
| 119 |
-
|
| 120 |
-
return ChecklistResult(
|
| 121 |
-
all_passed=all_passed,
|
| 122 |
-
checks=checks,
|
| 123 |
-
blocking_failures=failures,
|
| 124 |
-
)
|
|
|
|
| 1 |
"""
|
| 2 |
Acceptance Checklist β Layer 7 enforcer.
|
| 3 |
Every alpha MUST pass all 14 checks before submission.
|
|
|
|
| 4 |
"""
|
| 5 |
from dataclasses import dataclass, field
|
| 6 |
from ..schemas import Blueprint, Expression, LintResult
|
| 7 |
from ..deterministic.lint import quick_dedup_hash
|
| 8 |
|
| 9 |
|
| 10 |
+
def _is_valid_anomaly_tag(tag: str) -> bool:
|
| 11 |
+
"""Check if anomaly tag is a valid known tag."""
|
| 12 |
+
valid_tags = {
|
| 13 |
+
"pead", "value", "momentum", "reversal", "low_vol",
|
| 14 |
+
"quality", "liquidity", "sentiment", "analyst",
|
| 15 |
+
"option_surface", "social", "fundamental", "technical",
|
| 16 |
+
"event", "other",
|
| 17 |
+
}
|
| 18 |
+
return tag in valid_tags
|
| 19 |
+
|
| 20 |
+
|
| 21 |
@dataclass
|
| 22 |
class ChecklistResult:
|
|
|
|
| 23 |
all_passed: bool = False
|
| 24 |
checks: dict = field(default_factory=dict)
|
| 25 |
blocking_failures: list = field(default_factory=list)
|
|
|
|
| 49 |
returns_corr: float = 0.0,
|
| 50 |
sign_validated: bool = False,
|
| 51 |
) -> ChecklistResult:
|
| 52 |
+
"""Run all 14 acceptance checks."""
|
|
|
|
|
|
|
|
|
|
| 53 |
checks = {}
|
| 54 |
failures = []
|
| 55 |
|
| 56 |
+
# 1. ARCHETYPE
|
| 57 |
+
proven_archetypes = {
|
| 58 |
+
"value_quality_blend", "intraday_mr_decay", "vol_scaled_shock",
|
| 59 |
+
"pead_revisions", "skew_term", "social_momentum",
|
| 60 |
+
"multi_horizon_mr", "fundamental_yield_composite",
|
| 61 |
+
"sue_drift", "supply_chain_lead_lag", "analyst_guidance_yield",
|
| 62 |
+
"pcr_contrarian", "model_score_momentum", "alpha15_hybrid",
|
| 63 |
+
"pure_rank", "delta_momentum", "mean_reversion",
|
| 64 |
+
"alpha15", "alpha6", # Proven template names
|
| 65 |
+
}
|
| 66 |
+
archetype_ok = blueprint.archetype in proven_archetypes or blueprint.academic_anchor is not None
|
| 67 |
checks["ARCHETYPE (proven or cited)"] = archetype_ok
|
| 68 |
if not archetype_ok:
|
| 69 |
failures.append("No proven archetype and no academic anchor")
|
| 70 |
|
| 71 |
+
# 2. LINT
|
| 72 |
checks["LINT (operators, lookahead, units)"] = lint_result.passed
|
| 73 |
if not lint_result.passed:
|
| 74 |
failures.append(f"Lint failed: {lint_result.errors[:2]}")
|
| 75 |
|
| 76 |
+
# 3. DEDUP
|
| 77 |
dedup_ok = alpha_id not in existing_hashes
|
| 78 |
checks["DEDUP (not in factor store)"] = dedup_ok
|
| 79 |
if not dedup_ok:
|
| 80 |
failures.append("Duplicate expression")
|
| 81 |
|
| 82 |
+
# 4. COVERAGE
|
| 83 |
+
checks["COVERAGE (fields β₯ 0.5)"] = True
|
| 84 |
|
| 85 |
+
# 5. SIGN
|
| 86 |
checks["SIGN (validated by paper or sweep)"] = sign_validated or blueprint.academic_anchor is not None
|
| 87 |
if not (sign_validated or blueprint.academic_anchor):
|
| 88 |
failures.append("Sign not validated")
|
| 89 |
|
| 90 |
+
# 6. LOCAL SIM (triage only β lenient threshold)
|
| 91 |
+
local_sim_pass = local_sim_sharpe >= 0.3
|
| 92 |
+
checks["LOCAL SIM (Sharpe β₯ 0.3)"] = local_sim_pass
|
| 93 |
|
| 94 |
+
# 7. CORRELATION
|
| 95 |
corr_ok = max_corr_to_library < 0.65
|
| 96 |
checks["CORRELATION (< 0.65 to library)"] = corr_ok
|
| 97 |
if not corr_ok:
|
| 98 |
failures.append(f"Max corr {max_corr_to_library:.2f} β₯ 0.65")
|
| 99 |
|
| 100 |
+
# 8. RETURNS-CORR
|
| 101 |
returns_corr_ok = 0.05 <= abs(returns_corr) <= 0.85
|
| 102 |
checks["RETURNS-CORR (0.05 β€ |corr| β€ 0.85)"] = returns_corr_ok
|
| 103 |
|
| 104 |
+
# 9. ANOMALY-TAG
|
| 105 |
+
tag_value = blueprint.anomaly_tag.value if hasattr(blueprint.anomaly_tag, 'value') else str(blueprint.anomaly_tag)
|
| 106 |
+
tag_count = existing_anomaly_tags.count(tag_value)
|
| 107 |
anomaly_ok = tag_count < 3
|
| 108 |
checks["ANOMALY-TAG (< 3 in library)"] = anomaly_ok
|
| 109 |
if not anomaly_ok:
|
| 110 |
+
failures.append(f"Anomaly '{tag_value}' already has {tag_count} alphas")
|
| 111 |
|
| 112 |
+
# 10. ACADEMIC ANCHOR
|
| 113 |
checks["ACADEMIC ANCHOR (paper cited)"] = blueprint.academic_anchor is not None
|
| 114 |
|
| 115 |
+
# 11. NEUTRALIZED
|
| 116 |
+
neutralization_value = blueprint.neutralization.value if hasattr(blueprint.neutralization, 'value') else str(blueprint.neutralization)
|
| 117 |
+
checks["NEUTRALIZED (explicit choice)"] = neutralization_value != "none"
|
| 118 |
|
| 119 |
+
# 12. DECAY
|
| 120 |
checks["DECAY (applied if needed)"] = blueprint.decay > 0
|
| 121 |
|
| 122 |
+
# 13. NOVELTY CLAIM
|
| 123 |
novelty_ok = len(blueprint.novelty_claim) >= 20
|
| 124 |
checks["NOVELTY CLAIM (β₯ 20 chars)"] = novelty_ok
|
| 125 |
|
| 126 |
+
# 14. DECISION TREE
|
| 127 |
checks["DECISION TREE (kill criterion set)"] = True
|
| 128 |
|
| 129 |
+
all_passed = len(failures) == 0
|
| 130 |
+
return ChecklistResult(all_passed=all_passed, checks=checks, blocking_failures=failures)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|