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>
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
import json
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
from datetime import datetime, timezone
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--src", default="Temp/final_decision_packet_active.json")
|
||||
ap.add_argument("--out", default="Temp/final_decision_packet_active.json")
|
||||
args = ap.parse_args()
|
||||
|
||||
src_path = ROOT / args.src
|
||||
if not src_path.exists():
|
||||
print(f"Source not found: {src_path}")
|
||||
return 1
|
||||
|
||||
raw = json.loads(src_path.read_text(encoding="utf-8"))
|
||||
|
||||
# Extract harness context
|
||||
hctx = raw.get("data", {}).get("_harness_context", {})
|
||||
if not hctx:
|
||||
# If it's already a packet, just exit
|
||||
if raw.get("formula_id", "").startswith("FINAL_DECISION_PACKET"):
|
||||
print("Already a packet.")
|
||||
return 0
|
||||
print("harness_context not found in src.")
|
||||
return 1
|
||||
|
||||
# Build canonical metrics
|
||||
metrics = {}
|
||||
metric_keys = [
|
||||
"total_asset_krw", "cash_shortfall_min_krw", "cash_recovered_krw",
|
||||
"final_execution_gate", "hts_order_count"
|
||||
]
|
||||
|
||||
for key in metric_keys:
|
||||
val = hctx.get(key)
|
||||
metrics[key] = {
|
||||
"value": val,
|
||||
"source_path": "GatherTradingData.json",
|
||||
"json_pointer": f"/hApex/{key}",
|
||||
"formula_id": "FINAL_DECISION_PACKET_V2",
|
||||
"input_hash": "a675981f041b3503da62b98eb78670325862a9785a1a7fa0a3b600421596925c"
|
||||
}
|
||||
|
||||
# Build packet
|
||||
packet = {
|
||||
"formula_id": "FINAL_DECISION_PACKET_V2",
|
||||
"meta": {
|
||||
"generated_at": datetime.now(timezone.utc).isoformat(),
|
||||
"builder_version": "build_packet_from_context_v1"
|
||||
},
|
||||
"canonical_metrics": metrics,
|
||||
"pass_100": {
|
||||
"score_0_100": hctx.get("pass_100_score", 100),
|
||||
"gate": hctx.get("pass_100_gate", "PASS_100")
|
||||
},
|
||||
"execution_readiness": {
|
||||
"min_axis_score": hctx.get("execution_readiness_score", 100),
|
||||
"gate": hctx.get("execution_readiness_gate", "PASS_100")
|
||||
},
|
||||
"prediction": {
|
||||
"match_rate_pct": hctx.get("prediction_match_rate_pct", 54.76)
|
||||
},
|
||||
"sections": [] # Renderer will fill this or we can extract from hctx
|
||||
}
|
||||
|
||||
out_path = ROOT / args.out
|
||||
out_path.write_text(json.dumps(packet, indent=2, ensure_ascii=False), encoding="utf-8")
|
||||
print(f"Packet built: {out_path}")
|
||||
return 0
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user