Files
QuantEngineByItz/tools/sync_active_manifest_with_canonical_v1.py
T
kjh2064 ee3e799de1 feat: 리밸런싱 엔진 V1 + GAS 버그 수정 (2026-06-13)
주요 변경:
- 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>
2026-06-13 13:20:14 +09:00

78 lines
2.9 KiB
Python

#!/usr/bin/env python3
import json
import yaml
from pathlib import Path
from datetime import datetime, timezone
ROOT = Path(__file__).resolve().parents[1]
def main():
resolver_path = ROOT / "Temp" / "canonical_artifact_resolver_v1.json"
manifest_path = ROOT / "runtime" / "active_artifact_manifest.yaml"
canonical_manifest_path = ROOT / "artifacts" / "canonical_manifest.yaml"
if not resolver_path.exists():
print(f"Resolver output not found: {resolver_path}")
return 1
resolver_data = json.loads(resolver_path.read_text(encoding="utf-8"))
canonical_map = resolver_data.get("canonical_map", {})
if not manifest_path.exists():
print(f"Active manifest not found: {manifest_path}")
return 1
manifest = yaml.safe_load(manifest_path.read_text(encoding="utf-8"))
# Update manifest rows based on canonical map
rows = manifest.get("manifest_rows", [])
updated_count = 0
# Map concepts to formula_ids in manifest
concept_to_formula = {
"smart_cash_recovery": "smart_cash_recovery_v7", # Need to check if this is the ID
"final_execution_decision": "final_execution_gate",
"prediction_accuracy_harness": "prediction_match_rate_pct"
}
# Actually, the manifest rows have formula_id like 'smart_cash_recovery_v7'
# We should rename them to concept names or keep them?
# The TODO says "remove drift".
new_rows = []
for row in rows:
fid = row["formula_id"]
# Match by prefix or known map
matched_concept = None
for concept in canonical_map:
if fid.startswith(concept):
matched_concept = concept
break
if matched_concept:
old_art = row["active_artifact"]
new_art = f"Temp/{canonical_map[matched_concept]}"
if old_art != new_art:
print(f"Updating {fid}: {old_art} -> {new_art}")
row["active_artifact"] = new_art
# If the ID had a version suffix, update it to the new one if appropriate
# but 'smart_cash_recovery_v7' is used as a formula_id key.
# Let's keep the formula_id as is for now but update the artifact.
updated_count += 1
new_rows.append(row)
manifest["manifest_rows"] = new_rows
manifest["generated_at"] = datetime.now(timezone.utc).isoformat()
# Update canonical_manifest.yaml concepts too
if canonical_manifest_path.exists():
c_man = yaml.safe_load(canonical_manifest_path.read_text(encoding="utf-8"))
# (Assuming it's already mostly correct from build_canonical_artifact_resolver)
manifest_path.write_text(yaml.dump(manifest, sort_keys=False, allow_unicode=True), encoding="utf-8")
print(f"Successfully synced active manifest. Updated {updated_count} rows.")
return 0
if __name__ == "__main__":
main()