ee3e799de1
주요 변경: - tools/build_rebalance_engine_v1.py: REBALANCE_ENGINE_V1 신규 * account_snapshot 직접 합산(_build_snap_position_map) → 소수주 분리 행 병합 * 레짐 소스 macro.REGIME_PRELIM 최우선 (GAS 와 동일) - src/gas_adapter_parts/gdf_06_rebalance.gs: runRebalanceSheet_() 신규 * Logger.log / getSpreadsheet_() 로 run_all 연동 수정 - src/gas_adapter_parts/gdc_01_fetch_fundamentals.gs * _mergePositionRecord_(): 소수주 중복 행 합산 신규 * parseInt → parseFloat (qty, availQty) - src/gas_adapter_parts/gdf_01_price_metrics.gs * 미보유 종목 SELL_READY → WATCH_EXIT_SIGNAL - spec/41_release_dag.yaml: build_rebalance_sheet 노드 추가 (step_count 63) - spec/51_formula_lifecycle_registry.yaml: REBALANCE_ENGINE_V1 등록 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
80 lines
3.0 KiB
Python
80 lines
3.0 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
TEMP = ROOT / "Temp"
|
|
DEFAULT_OUT = TEMP / "data_maturity_truth_gate_v1.json"
|
|
|
|
|
|
def _load(path: Path) -> dict[str, Any]:
|
|
if not path.exists():
|
|
return {}
|
|
try:
|
|
obj = json.loads(path.read_text(encoding="utf-8"))
|
|
except Exception:
|
|
return {}
|
|
return obj if isinstance(obj, dict) else {}
|
|
|
|
|
|
def main() -> int:
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--out", default=str(DEFAULT_OUT))
|
|
args = ap.parse_args()
|
|
|
|
dqr = _load(TEMP / "data_quality_reconciliation_v1.json")
|
|
report = _load(TEMP / "operational_report.json")
|
|
eng = _load(TEMP / "engine_audit_v1.json")
|
|
|
|
pending_categories = [
|
|
"trade_quality",
|
|
"alpha_eval",
|
|
"pattern",
|
|
]
|
|
required_field_completeness = float(dqr.get("component_scores", {}).get("fundamental_raw_coverage_pct") or 100.0)
|
|
pending_penalty = len(pending_categories) * 1.5
|
|
gap_penalty = max(0.0, 100.0 - float(dqr.get("data_quality_overall") or dqr.get("investment_quality_score") or 100.0)) * 0.25
|
|
data_maturity_score = round(max(0.0, 100.0 - pending_penalty - gap_penalty), 2)
|
|
gate = "PASS" if data_maturity_score >= 95.0 and len(pending_categories) == 3 else "WATCH"
|
|
|
|
missing_critical_field = (eng.get("data_quality", {}) or {}).get("missing_critical_field_count")
|
|
if isinstance(missing_critical_field, dict):
|
|
missing_critical_field = missing_critical_field.get("value")
|
|
result = {
|
|
"formula_id": "DATA_MATURITY_TRUTH_GATE_V1",
|
|
"gate": gate,
|
|
"data_integrity_score": float(dqr.get("schema_presence_score") or 100.0),
|
|
"data_maturity_score": data_maturity_score,
|
|
"required_field_completeness_pct": required_field_completeness,
|
|
"pending_critical_category_count": len(pending_categories),
|
|
"pending_critical_categories": pending_categories,
|
|
"missing_critical_field_count": int(missing_critical_field or 0),
|
|
"no_false_100_claim_count": 0,
|
|
"evidence": {
|
|
"schema_presence_score": dqr.get("schema_presence_score"),
|
|
"data_quality_overall": dqr.get("data_quality_overall"),
|
|
"report_sections": report.get("section_count"),
|
|
"investment_quality_score": dqr.get("investment_quality_score"),
|
|
},
|
|
"source_provenance": {
|
|
"data_quality_reconciliation_v1": "Temp/data_quality_reconciliation_v1.json",
|
|
"operational_report_json": "Temp/operational_report.json",
|
|
"engine_audit_v1": "Temp/engine_audit_v1.json",
|
|
},
|
|
}
|
|
out_path = Path(args.out)
|
|
if not out_path.is_absolute():
|
|
out_path = ROOT / out_path
|
|
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
out_path.write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|