diff --git a/docs/ROADMAP_WBS.md b/docs/ROADMAP_WBS.md index 0e9c388..47ec2e8 100644 --- a/docs/ROADMAP_WBS.md +++ b/docs/ROADMAP_WBS.md @@ -36,7 +36,7 @@ | **D2 공식 결정론** | 149개 공식 ID 전부 lifecycle 등록 | 269개 등록 (100%) ✅ | | **D3 리스크 제어** | Core/Satellite/Cash 버킷 밴드 위반 0건 | RISK_ON 밴드 내 유지 중 | | **D4 알파 피드백** | 예측→실현 수익 루프 30건 이상 누적 | 0건 (DATA_GATED ~2026-07-15) | -| **D5 실행 자동화** | run_all 1회 실행으로 전체 파이프라인 완결 | 96단계 DAG 구축 완료 ✅ | +| **D5 실행 자동화** | run_all 1회 실행으로 전체 파이프라인 완결 | 98단계 DAG 구축 완료 ✅ | --- @@ -586,7 +586,7 @@ CI 게이트: honest_proof_score: 50.95 → 목표: ≥70 (T+20 30건 → 70.95 자동 달성 예상) 자동화: - run_all 성공률: 96단계 DAG PASS → 목표: ≥95% ✅ (step_count=96, wave_0~9) + run_all 성공률: 98단계 DAG PASS → 목표: ≥95% ✅ (step_count=98, wave_0~9) CI/CD 커버리지: 100% → 목표: 100% ✅ (Synology act_runner 온라인, 4게이트 PASS) 수동 개입 횟수: 매일 → 목표: ≤1회/주 (setupDailyRunAllTrigger 설정 후) ``` diff --git a/package.json b/package.json index 8f16ada..e3a9feb 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,13 @@ "build-prediction-accuracy-harness": "python tools/build_prediction_accuracy_harness_v2.py", "build-alpha-feedback-loop": "python tools/build_alpha_feedback_loop_v2.py", "build-operational-alpha-calibration": "python tools/build_operational_alpha_calibration_v2.py", + "build-sector-flow-history-progress": "python tools/build_sector_flow_history_progress_v1.py", "build-realized-performance": "python tools/build_realized_performance_v1.py", "validate-completion-harness": "python tools/validate_completion_harness_instructions_v1.py", "validate-prediction-accuracy-harness": "python tools/validate_prediction_accuracy_harness_v2.py", "validate-alpha-feedback-loop": "python tools/validate_alpha_feedback_loop_v2.py", "validate-operational-alpha-calibration": "python tools/validate_operational_alpha_calibration_v2.py", + "validate-sector-flow-history-progress": "python tools/validate_sector_flow_history_progress_v1.py", "validate-realized-performance": "python tools/validate_realized_performance_v1.py", "validate-gas-recovery": "python tools/validate_gas_orchestration_recovery_v1.py", "ops:clean": "python tools/clean_temp_artifacts_v1.py", diff --git a/runtime/refactor_baseline_v1.yaml b/runtime/refactor_baseline_v1.yaml index db1bfdb..3645728 100644 --- a/runtime/refactor_baseline_v1.yaml +++ b/runtime/refactor_baseline_v1.yaml @@ -1,9 +1,9 @@ { "formula_id": "AUDIT_REPOSITORY_ENTROPY_V2", "gate": "PASS", - "total_file_count": 1890, - "package_script_count": 29, - "temp_json_count": 191, + "total_file_count": 1894, + "package_script_count": 31, + "temp_json_count": 193, "budget": { "schema_version": "repository_entropy_budget.v1", "max_total_files": 2200, @@ -15,5 +15,5 @@ "keep package scripts within release envelope" ] }, - "source_zip_sha256": "1b582cc260c09b41dfd2c361bdd40705ac003b88ad8a09b42bbba615189cbf2b" + "source_zip_sha256": "ce6afd425a6dbabb4bc4876703080a9dd639077ed52a8bca9ffa39452982c309" } \ No newline at end of file diff --git a/spec/41_release_dag.yaml b/spec/41_release_dag.yaml index 33636d6..600cc09 100644 --- a/spec/41_release_dag.yaml +++ b/spec/41_release_dag.yaml @@ -1,5 +1,5 @@ schema_version: release_dag.v3 -step_count: 96 +step_count: 98 goal: Linearize package.json scripts into a validated DAG execution graph. execution_order: # 토폴로지 정렬 기준 병렬 실행 wave (의존성 없는 노드들을 동시에 실행 가능) @@ -42,6 +42,7 @@ execution_order: - build_etf_representative_monitor - build_factor_shadow_eligibility - build_formula_outputs + - build_sector_flow_history_progress - build_realized_performance - build_missing_formula_bridge - build_ratchet_trailing_general @@ -89,6 +90,7 @@ execution_order: - build_honest_proof_gap_analyzer - build_operational_alpha_calibration - build_prediction_accuracy_harness + - validate_sector_flow_history_progress - validate_json_generator_outputs - validate_alpha_feedback_loop - validate_llm_copy_only @@ -157,6 +159,18 @@ dag: artifact_policy: "keep" note: "DATA_GATED 항목별 실측 진척도 — non-blocking diagnostic" + build_sector_flow_history_progress: + id: build_sector_flow_history_progress + command: ["python", "tools/build_sector_flow_history_progress_v1.py"] + inputs: ["tools/build_sector_flow_history_progress_v1.py", "GatherTradingData.json"] + outputs: ["Temp/sector_flow_history_progress_v1.json"] + depends_on: ["build_data_gated_progress"] + timeout_sec: 30 + cache_key: "build_sector_flow_history_progress_v1" + strict: false + artifact_policy: "keep" + note: "WBS-2.5 sector_flow_history 30일 누적 진척도 — non-blocking diagnostic" + build_realized_performance: id: build_realized_performance command: ["python", "tools/build_realized_performance_v1.py"] @@ -634,6 +648,17 @@ dag: strict: true artifact_policy: "keep" + validate_sector_flow_history_progress: + id: validate_sector_flow_history_progress + command: ["python", "tools/validate_sector_flow_history_progress_v1.py"] + inputs: ["tools/validate_sector_flow_history_progress_v1.py", "Temp/sector_flow_history_progress_v1.json"] + outputs: ["Temp/validate_sector_flow_history_progress_v1.json"] + depends_on: ["build_sector_flow_history_progress"] + timeout_sec: 30 + cache_key: "validate_sector_flow_history_progress_v1" + strict: true + artifact_policy: "keep" + validate_alpha_feedback_loop: id: validate_alpha_feedback_loop command: ["python", "tools/validate_alpha_feedback_loop_v2.py"] @@ -1289,7 +1314,7 @@ dag: command: ["python", "tools/prepare_upload_zip.py", "--skip-validate", "--skip-convert", "--validation-mode", "package-only"] inputs: ["tools/prepare_upload_zip.py"] outputs: [] - depends_on: ["audit_entropy", "validate_specs", "validate_active_manifest", "validate_report_sync", "validate_report_numeric_consistency", "validate_field_dict", "validate_provenance", "validate_low_capability", "validate_golden_coverage", "validate_calibration", "validate_schema_model", "validate_gas_adapter", "validate_agents_shrink", "validate_no_replay_live_mix", "validate_prediction_accuracy_harness", "validate_alpha_feedback_loop", "validate_operational_alpha_calibration", "validate_realized_performance", "validate_runtime_source_whitelist", "validate_cash_ledger", "validate_factor_lifecycle", "validate_factor_lifecycle_completeness", "validate_metric_alias_collision", "validate_architecture_boundaries", "validate_module_io_coverage", "validate_artifact_chain_hash", "validate_artifact_sync", "validate_renderer_no_calc", "validate_packaged_refs", "validate_property_invariants", "validate_anti_late_entry", "validate_rule_lifecycle", "validate_change_requests", "validate_completion_harness_instructions", "validate_engine_health_card", "validate_llm_regression", "validate_llm_copy_only", "build_final_decision", "build_final_context", "build_provenance_ledger", "build_live_replay_separation", "build_late_chase_attribution", "build_profit_giveback_ratchet", "build_shadow_ledger", "build_operating_cadence_signal", "build_engine_health_card", "build_module_io_coverage", "build_artifact_chain_hash", "build_report", "build_bundle", "build_schema_models", "build_architecture_boundaries", "validate_decision_trace", "validate_factor_conflicts", "validate_no_lookahead", "validate_execution_sim", "validate_render_diff", "build_shadow_promotion", "validate_llm_determinism", "build_time_stop_forecast", "validate_live_activation", "build_rebalance_sheet", "build_prediction_accuracy_harness", "build_alpha_feedback_loop", "build_operational_alpha_calibration"] + depends_on: ["audit_entropy", "validate_specs", "validate_active_manifest", "validate_report_sync", "validate_report_numeric_consistency", "validate_field_dict", "validate_provenance", "validate_low_capability", "validate_golden_coverage", "validate_calibration", "validate_schema_model", "validate_gas_adapter", "validate_agents_shrink", "validate_no_replay_live_mix", "validate_prediction_accuracy_harness", "validate_alpha_feedback_loop", "validate_operational_alpha_calibration", "validate_realized_performance", "validate_sector_flow_history_progress", "validate_runtime_source_whitelist", "validate_cash_ledger", "validate_factor_lifecycle", "validate_factor_lifecycle_completeness", "validate_metric_alias_collision", "validate_architecture_boundaries", "validate_module_io_coverage", "validate_artifact_chain_hash", "validate_artifact_sync", "validate_renderer_no_calc", "validate_packaged_refs", "validate_property_invariants", "validate_anti_late_entry", "validate_rule_lifecycle", "validate_change_requests", "validate_completion_harness_instructions", "validate_engine_health_card", "validate_llm_regression", "validate_llm_copy_only", "build_final_decision", "build_final_context", "build_provenance_ledger", "build_live_replay_separation", "build_late_chase_attribution", "build_profit_giveback_ratchet", "build_shadow_ledger", "build_operating_cadence_signal", "build_engine_health_card", "build_module_io_coverage", "build_artifact_chain_hash", "build_report", "build_bundle", "build_schema_models", "build_architecture_boundaries", "validate_decision_trace", "validate_factor_conflicts", "validate_no_lookahead", "validate_execution_sim", "validate_render_diff", "build_shadow_promotion", "validate_llm_determinism", "build_time_stop_forecast", "validate_live_activation", "build_rebalance_sheet", "build_prediction_accuracy_harness", "build_alpha_feedback_loop", "build_operational_alpha_calibration", "build_sector_flow_history_progress"] timeout_sec: 60 cache_key: "prepare_zip_v1" strict: true diff --git a/src/quant_engine/prepare_upload_zip.py b/src/quant_engine/prepare_upload_zip.py index fc408f6..6c079c3 100644 --- a/src/quant_engine/prepare_upload_zip.py +++ b/src/quant_engine/prepare_upload_zip.py @@ -94,6 +94,8 @@ TEMP_KEEP_FILES = { "validate_alpha_feedback_loop_v2.json", "operational_alpha_calibration_v2.json", "validate_operational_alpha_calibration_v2.json", + "sector_flow_history_progress_v1.json", + "validate_sector_flow_history_progress_v1.json", "realized_performance_v1.json", "validate_realized_performance_v1.json", "single_truth_ledger_v2.json", diff --git a/tools/build_sector_flow_history_progress_v1.py b/tools/build_sector_flow_history_progress_v1.py new file mode 100644 index 0000000..1a5b6ec --- /dev/null +++ b/tools/build_sector_flow_history_progress_v1.py @@ -0,0 +1,91 @@ +"""build_sector_flow_history_progress_v1.py — SECTOR_FLOW_HISTORY_PROGRESS_V1 + +WBS-2.5 진척도를 실데이터로 요약한다. +sector_flow_history 누적 일수와 Flow_Credit 커버리지를 정직하게 노출한다. +""" +from __future__ import annotations + +import argparse +import json +from collections import defaultdict +from pathlib import Path +from typing import Any + +ROOT = Path(__file__).resolve().parents[1] +DEFAULT_JSON = ROOT / "GatherTradingData.json" +DEFAULT_OUT = ROOT / "Temp" / "sector_flow_history_progress_v1.json" +FORMULA_ID = "SECTOR_FLOW_HISTORY_PROGRESS_V1" + + +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 _rows(data: dict[str, Any], key: str) -> list[dict[str, Any]]: + rows = (data.get("data") or {}).get(key) or [] + return [r for r in rows if isinstance(r, dict)] + + +def main() -> int: + ap = argparse.ArgumentParser() + ap.add_argument("--json", default=str(DEFAULT_JSON)) + ap.add_argument("--out", default=str(DEFAULT_OUT)) + args = ap.parse_args() + + json_path = Path(args.json) + json_path = json_path if json_path.is_absolute() else ROOT / json_path + out_path = Path(args.out) + out_path = out_path if out_path.is_absolute() else ROOT / out_path + + payload = _load(json_path) + sector_rows = _rows(payload, "sector_flow_history") + data_feed_rows = _rows(payload, "data_feed") + + by_date: dict[str, int] = defaultdict(int) + for row in sector_rows: + snap = row.get("Snapshot_Date") or row.get("snapshot_date") or "" + day = str(snap)[:10] + if day: + by_date[day] += 1 + + distinct_dates = len(by_date) + row_count = len(sector_rows) + target_dates = 30 + status = "DONE" if distinct_dates >= target_dates else "DATA_GATED" + coverage = round(min(100.0, distinct_dates / target_dates * 100.0), 2) + + flow_credit_values = [row.get("Flow_Credit") for row in data_feed_rows] + nonnull_flow_credit = sum(1 for v in flow_credit_values if v is not None) + flow_credit_coverage = round((nonnull_flow_credit / len(flow_credit_values) * 100.0), 2) if flow_credit_values else 0.0 + + result = { + "formula_id": FORMULA_ID, + "status": status, + "current_dates": distinct_dates, + "target_dates": target_dates, + "coverage_pct": coverage, + "row_count": row_count, + "rows_per_date": sorted(by_date.items()), + "flow_credit_coverage_pct": flow_credit_coverage, + "flow_credit_nonnull_count": nonnull_flow_credit, + "flow_credit_total_count": len(flow_credit_values), + "source": "GatherTradingData.json:data.sector_flow_history + data.data_feed", + } + + out_path.parent.mkdir(parents=True, exist_ok=True) + out_path.write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") + print( + f"[{FORMULA_ID}] status={status} dates={distinct_dates}/{target_dates} " + f"rows={row_count} flow_credit={nonnull_flow_credit}/{len(flow_credit_values)}" + ) + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tools/validate_sector_flow_history_progress_v1.py b/tools/validate_sector_flow_history_progress_v1.py new file mode 100644 index 0000000..2906cf4 --- /dev/null +++ b/tools/validate_sector_flow_history_progress_v1.py @@ -0,0 +1,79 @@ +"""validate_sector_flow_history_progress_v1.py — SECTOR_FLOW_HISTORY_PROGRESS_VALIDATE_V1 + +sector_flow_history 진척도 산출물의 기본 계약을 검증한다. +""" +from __future__ import annotations + +import argparse +import json +from pathlib import Path +from typing import Any + +ROOT = Path(__file__).resolve().parents[1] +DEFAULT_INPUT = ROOT / "Temp" / "sector_flow_history_progress_v1.json" +DEFAULT_OUT = ROOT / "Temp" / "validate_sector_flow_history_progress_v1.json" +FORMULA_ID = "SECTOR_FLOW_HISTORY_PROGRESS_VALIDATE_V1" + + +def _load(path: Path) -> Any: + if not path.exists(): + return {} + try: + return json.loads(path.read_text(encoding="utf-8")) + except Exception: + return {} + + +def main() -> int: + ap = argparse.ArgumentParser() + ap.add_argument("--input", default=str(DEFAULT_INPUT)) + ap.add_argument("--out", default=str(DEFAULT_OUT)) + args = ap.parse_args() + + input_path = Path(args.input) + input_path = input_path if input_path.is_absolute() else ROOT / input_path + out_path = Path(args.out) + out_path = out_path if out_path.is_absolute() else ROOT / out_path + + payload = _load(input_path) + errors: list[str] = [] + + if not isinstance(payload, dict) or not payload: + errors.append("payload must be object") + else: + if payload.get("formula_id") != "SECTOR_FLOW_HISTORY_PROGRESS_V1": + errors.append("formula_id mismatch") + if payload.get("status") not in {"DONE", "DATA_GATED"}: + errors.append(f"status={payload.get('status')}") + for key in [ + "current_dates", + "target_dates", + "coverage_pct", + "row_count", + "rows_per_date", + "flow_credit_coverage_pct", + ]: + if key not in payload: + errors.append(f"missing field: {key}") + + current_dates = payload.get("current_dates") + target_dates = payload.get("target_dates") + if isinstance(current_dates, int) and isinstance(target_dates, int): + if current_dates < target_dates and payload.get("status") != "DATA_GATED": + errors.append("current_dates < target_dates requires DATA_GATED") + if current_dates >= target_dates and payload.get("status") != "DONE": + errors.append("current_dates >= target_dates requires DONE") + + result = { + "formula_id": FORMULA_ID, + "gate": "PASS" if not errors else "FAIL", + "checked_file": str(Path(args.input).as_posix()), + "errors": errors, + } + out_path.write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n", encoding="utf-8") + print(json.dumps(result, ensure_ascii=False, indent=2)) + return 0 if not errors else 1 + + +if __name__ == "__main__": + raise SystemExit(main())