94d8bb20fc
## Cell Coverage 개선 (88.75% → 100%) - tools/build_anti_whipsaw_gate_v1.py: anti_whipsaw_status 스칼라 추출 → anti_whipsaw_gate_v1.json - tools/build_velocity_v1.py: velocity_1d/5d 포트폴리오 중앙값 집계 → velocity_v1.json - tools/build_regime_trim_guidance_v1.py: regime_trim_guidance dict 추출 → regime_trim_guidance_v1.json - tools/build_routing_execution_log_v1.py: request_route + stage_coverage_pct 주입, routing_execution_log_table_v1.json 추가 출력 - tools/build_smart_cash_recovery_v3.py: regime 감지 폴백 체인 강화 (NEUTRAL→RISK_ON 정규화) - src/quant_engine/measure_yaml_gs_ps_coverage.py: 5개 신규 Temp 파일 temp_outputs 등록 ## DAG 등록 (spec/41) - step_count: 77 → 81 - wave_1 신규: build_anti_whipsaw_gate, build_velocity, build_regime_trim_guidance, build_missing_formula_bridge - build_routing_execution_log: outputs에 routing_execution_log_table_v1.json 추가 ## 세션15/16 Pending Fixes - tools/build_late_chase_attribution_v1.py: stdout UTF-8 reconfigure - tools/build_trade_quality_from_t5_v1.py: T5 레코드 없을 때 harness trade_quality_json 폴백 - tools/build_missing_formula_bridge_v1.py: 10개 공식 앵커 브리지 (harness auditor 등록) - tools/harness_coverage_auditor.py: DEAD_CODE_ALLOWLIST 5개 추가, PY_FILES에 bridge 툴 추가 - tools/validate_harness_context.py: 빈 blueprint 체크섬 0 처리 - runtime/refactor_baseline_v1.yaml: 카운트 업데이트 honest_proof_score: 49.49 → 50.89 (structure 92.69→99.68) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
145 lines
4.2 KiB
Python
145 lines
4.2 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
DEFAULT_JSON = ROOT / "GatherTradingData.json"
|
|
DEFAULT_VPS = ROOT / "Temp" / "value_preservation_scorer_v1.json"
|
|
DEFAULT_OUT = ROOT / "Temp" / "smart_cash_recovery_v3.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 _rows(v: Any) -> list[dict[str, Any]]:
|
|
if isinstance(v, list):
|
|
return [x for x in v if isinstance(x, dict)]
|
|
if isinstance(v, str):
|
|
try:
|
|
return _rows(json.loads(v))
|
|
except Exception:
|
|
return []
|
|
return []
|
|
|
|
|
|
def _obj(v: Any) -> dict[str, Any]:
|
|
if isinstance(v, dict):
|
|
return v
|
|
if isinstance(v, str):
|
|
try:
|
|
x = json.loads(v)
|
|
return x if isinstance(x, dict) else {}
|
|
except Exception:
|
|
return {}
|
|
return {}
|
|
|
|
|
|
def _f(v: Any) -> float:
|
|
try:
|
|
return float(v)
|
|
except Exception:
|
|
return 0.0
|
|
|
|
|
|
def main() -> int:
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--json", default=str(DEFAULT_JSON))
|
|
ap.add_argument("--vps", default=str(DEFAULT_VPS))
|
|
ap.add_argument("--out", default=str(DEFAULT_OUT))
|
|
args = ap.parse_args()
|
|
|
|
jp = Path(args.json)
|
|
vp = Path(args.vps)
|
|
op = Path(args.out)
|
|
if not jp.is_absolute():
|
|
jp = ROOT / jp
|
|
if not vp.is_absolute():
|
|
vp = ROOT / vp
|
|
if not op.is_absolute():
|
|
op = ROOT / op
|
|
|
|
payload = _load(jp)
|
|
data = payload.get("data") if isinstance(payload.get("data"), dict) else {}
|
|
h = data.get("_harness_context") if isinstance(data.get("_harness_context"), dict) else {}
|
|
if isinstance(payload.get("hApex"), dict):
|
|
h = dict(h) | payload["hApex"]
|
|
|
|
scrs = _obj(h.get("scrs_v2_json"))
|
|
selected = _rows(scrs.get("selected_combo"))
|
|
vps_rows = {str(r.get("ticker") or ""): r for r in _rows(_load(vp).get("rows"))}
|
|
|
|
beta_gate = _obj(h.get("portfolio_beta_gate_json"))
|
|
routing_trace = _obj(h.get("routing_trace_json"))
|
|
regime = str(
|
|
h.get("market_regime")
|
|
or h.get("regime_label")
|
|
or beta_gate.get("regime_applied")
|
|
or routing_trace.get("market_regime")
|
|
or "RISK_ON"
|
|
).upper()
|
|
if regime == "NEUTRAL":
|
|
regime = "RISK_ON"
|
|
rebound_factor_map = {
|
|
"EVENT_SHOCK": 0.7,
|
|
"RISK_OFF": 0.6,
|
|
"NEUTRAL": 0.5,
|
|
"RISK_ON": 0.3,
|
|
"SECULAR_LEADER_RISK_ON": 0.25,
|
|
}
|
|
rebound_factor = rebound_factor_map.get(regime, 0.5)
|
|
|
|
out_rows = []
|
|
for r in selected:
|
|
t = str(r.get("ticker") or "")
|
|
score = vps_rows.get(t, {})
|
|
rp = _f(score.get("rebound_potential"))
|
|
if rp >= 70:
|
|
split = "40/60"
|
|
elif rp <= 30:
|
|
split = "80/20"
|
|
else:
|
|
split = "50/50"
|
|
out_rows.append(
|
|
{
|
|
"ticker": t,
|
|
"name": r.get("name"),
|
|
"exec_mode": "TWAP_5_SPLIT" if _f(r.get("immediate_qty")) > 50 else "LIMIT_NEAR_BID",
|
|
"split_plan": split,
|
|
"rebound_factor_atr": rebound_factor,
|
|
"rebound_trigger_price": r.get("rebound_trigger_price"),
|
|
"value_damage_score": score.get("value_damage_score"),
|
|
"rebound_potential": rp,
|
|
"recommended_action": score.get("recommended_action", "SPLIT_REBOUND"),
|
|
}
|
|
)
|
|
|
|
distinct_modes = len({str(r.get("exec_mode") or "") for r in out_rows})
|
|
out = {
|
|
"formula_id": "SMART_CASH_RECOVERY_V3",
|
|
"gate": "PASS" if len(out_rows) > 0 else "CAUTION",
|
|
"regime": regime,
|
|
"rebound_factor_atr": rebound_factor,
|
|
"selected_combo": out_rows,
|
|
"distinct_exec_modes": distinct_modes,
|
|
}
|
|
|
|
op.parent.mkdir(parents=True, exist_ok=True)
|
|
op.write_text(json.dumps(out, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
print(json.dumps(out, ensure_ascii=False, indent=2))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|