WBS-7.3: GAS→Python 마이그레이션 5개 항목 완료 (F14, F02-F06)
- F14: late_chase_risk_score 검증 * GAS가 유일한 생산처 (Python canonical 없음) * migration_action: KEEP_IN_GAS로 정정, status: DONE - F02/F03/F04/F06: priceBasis 로직 포팅 * formulas/price_basis_v1.py: select_price_basis_tier2/tier1 구현 * tests/parity/test_price_basis_parity_v1.py: 8 parity 테스트 (모두 PASS) * GAS Number.isFinite() 의미론 정확히 재현 (math.isfinite 사용) * 모든 테스트 112/112 PASS 남은 작업 (4개): - F05: decision_logic (action assignment) - F07: score_logic (threshold addition) - F10: routing decision - F15: late_chase_gate Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
import yaml
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
def main() -> int:
|
||||
taxonomy_path = ROOT / "spec" / "43_quant_factor_taxonomy.yaml"
|
||||
registry_path = ROOT / "spec" / "factor_lifecycle_registry.yaml"
|
||||
|
||||
if not taxonomy_path.exists():
|
||||
print(f"Taxonomy spec missing: {taxonomy_path}")
|
||||
return 1
|
||||
if not registry_path.exists():
|
||||
print(f"Registry spec missing: {registry_path}")
|
||||
return 1
|
||||
|
||||
try:
|
||||
tax_data = yaml.safe_load(taxonomy_path.read_text(encoding="utf-8")) or {}
|
||||
required_fields = tax_data.get("required_lifecycle_fields", [])
|
||||
except Exception as e:
|
||||
print(f"Failed to parse taxonomy: {e}")
|
||||
return 1
|
||||
|
||||
try:
|
||||
reg_data = yaml.safe_load(registry_path.read_text(encoding="utf-8")) or {}
|
||||
factors = reg_data.get("factors", [])
|
||||
except Exception as e:
|
||||
print(f"Failed to parse registry: {e}")
|
||||
return 1
|
||||
|
||||
required_field_missing_count = 0
|
||||
active_factor_without_shadow_evidence_count = 0
|
||||
errors = []
|
||||
|
||||
for factor in factors:
|
||||
if not isinstance(factor, dict):
|
||||
continue
|
||||
fid = factor.get("factor_id", "UNKNOWN")
|
||||
gate = str(factor.get("promotion_gate", "draft")).lower()
|
||||
|
||||
# Enforce lifecycle constraints on active factors
|
||||
if gate == "active":
|
||||
# 1. Check all required lifecycle fields from taxonomy
|
||||
missing_fields = []
|
||||
for field in required_fields:
|
||||
if field not in factor and field != "input_fields": # input_fields is represented by required_data in our registry
|
||||
missing_fields.append(field)
|
||||
if "required_data" not in factor and "input_fields" not in factor:
|
||||
missing_fields.append("input_fields")
|
||||
|
||||
if missing_fields:
|
||||
required_field_missing_count += len(missing_fields)
|
||||
errors.append(f"Active factor '{fid}' is missing required fields: {missing_fields}")
|
||||
|
||||
# 2. Check for shadow evidence (shadow_start_date must be present and valid)
|
||||
shadow_start = factor.get("shadow_start_date")
|
||||
if not shadow_start:
|
||||
active_factor_without_shadow_evidence_count += 1
|
||||
errors.append(f"Active factor '{fid}' has no shadow_start_date (no shadow evidence)")
|
||||
|
||||
# 3. Check for golden cases (golden_cases must be non-empty)
|
||||
golden = factor.get("golden_cases")
|
||||
if not golden:
|
||||
required_field_missing_count += 1
|
||||
errors.append(f"Active factor '{fid}' must have non-empty golden_cases")
|
||||
|
||||
gate_passed = (required_field_missing_count == 0) and (active_factor_without_shadow_evidence_count == 0)
|
||||
|
||||
result = {
|
||||
"formula_id": "FACTOR_LIFECYCLE_REGISTRY_VALIDATOR_V1",
|
||||
"factor_required_field_missing_count": required_field_missing_count,
|
||||
"active_factor_without_shadow_evidence_count": active_factor_without_shadow_evidence_count,
|
||||
"errors": errors,
|
||||
"gate": "PASS" if gate_passed else "FAIL"
|
||||
}
|
||||
|
||||
# Write to Temp
|
||||
out_dir = ROOT / "Temp"
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
out_path = out_dir / "factor_lifecycle_registry_validation_v1.json"
|
||||
out_path.write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
|
||||
print(json.dumps(result, ensure_ascii=True, indent=2))
|
||||
return 0 if gate_passed else 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user