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,114 @@
|
||||
"""build_vacuous_pass_audit_v1.py — NON_VACUOUS_PASS_GUARD_V1
|
||||
|
||||
RC2 수정: row_count=0 / sample_n < min_samples 게이트가 PASS로 집계되어
|
||||
점수를 부풀리는 문제 감지. 미달 게이트를 WATCH_PENDING_SAMPLE로 강제 강등.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
from v7_hardening_common import ROOT, TEMP, save_json
|
||||
|
||||
MIN_SAMPLES_DEFAULT = 30
|
||||
|
||||
EFFECTIVE_N_FIELDS = ["sample_count", "row_count", "evaluated_count", "samples", "n",
|
||||
"sample_n", "cases_analyzed", "t5_sample", "t20_sample",
|
||||
"op_t5_sample", "op_t20_sample"]
|
||||
|
||||
KNOWN_VACUOUS_GATES = [
|
||||
# (file_stem, gate_field, n_field, label)
|
||||
("value_preservation_scorer_v2", "gate", "row_count", "VALUE_PRESERVATION_SCORER_V2"),
|
||||
("rebound_sell_efficiency_v1", "gate", "sample_n", "rebound_efficiency_score"),
|
||||
("late_rebound_bucket_score_v1", "gate", "sample_n", "late_rebound_bucket_score"),
|
||||
("late_chase_attribution_v4", "gate", "samples", "late_chase_attribution_v4"),
|
||||
("smart_money_liquidity_evidence_gate_v5", "gate", "sample_count", "smart_money_liquidity_evidence"),
|
||||
("live_trade_outcome_ledger_v1", "gate", "live_count", "live_trade_outcome_ledger"),
|
||||
]
|
||||
|
||||
|
||||
def _get_effective_n(obj: dict) -> int | None:
|
||||
for field in EFFECTIVE_N_FIELDS:
|
||||
val = obj.get(field)
|
||||
if val is not None:
|
||||
try:
|
||||
return int(val)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
def _audit_known_gates(violations: list, demotions: list) -> None:
|
||||
for file_stem, gate_field, n_field, label in KNOWN_VACUOUS_GATES:
|
||||
path = TEMP / f"{file_stem}.json"
|
||||
if not path.exists():
|
||||
continue
|
||||
try:
|
||||
obj = json.loads(path.read_text(encoding="utf-8"))
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
gate_val = str(obj.get(gate_field) or "").upper()
|
||||
n_val = _get_effective_n({n_field: obj.get(n_field)})
|
||||
if n_val is None:
|
||||
n_val = _get_effective_n(obj)
|
||||
|
||||
if n_val is None:
|
||||
n_val = 0
|
||||
|
||||
is_pass = gate_val == "PASS"
|
||||
is_low_n = n_val < MIN_SAMPLES_DEFAULT
|
||||
|
||||
if is_pass and is_low_n:
|
||||
label_str = f"[PASS_INVALID_LOW_N: n={n_val} < {MIN_SAMPLES_DEFAULT}]"
|
||||
violations.append({
|
||||
"formula": label,
|
||||
"file": str(path.name),
|
||||
"gate_field": gate_field,
|
||||
"gate_value": gate_val,
|
||||
"effective_n": n_val,
|
||||
"min_samples": MIN_SAMPLES_DEFAULT,
|
||||
"required_demotion": "WATCH_PENDING_SAMPLE",
|
||||
"label": label_str,
|
||||
})
|
||||
elif is_low_n and gate_val not in ("", "UNKNOWN"):
|
||||
demotions.append({
|
||||
"formula": label,
|
||||
"file": str(path.name),
|
||||
"gate_field": gate_field,
|
||||
"gate_value": gate_val,
|
||||
"effective_n": n_val,
|
||||
"min_samples": MIN_SAMPLES_DEFAULT,
|
||||
"status": "ALREADY_NON_PASS" if not is_pass else "WATCH_PENDING_SAMPLE",
|
||||
})
|
||||
|
||||
|
||||
def main() -> int:
|
||||
violations: list = []
|
||||
demotions: list = []
|
||||
|
||||
_audit_known_gates(violations, demotions)
|
||||
|
||||
vacuous_pass_count = len(violations)
|
||||
gate = "PASS" if vacuous_pass_count == 0 else "FAIL"
|
||||
|
||||
result = {
|
||||
"formula_id": "NON_VACUOUS_PASS_GUARD_V1",
|
||||
"gate": gate,
|
||||
"vacuous_pass_gate_count": vacuous_pass_count,
|
||||
"min_samples_default": MIN_SAMPLES_DEFAULT,
|
||||
"violations": violations,
|
||||
"demotions_already_non_pass": demotions,
|
||||
"enforcement_note": (
|
||||
"PASS 분자에 포함 금지: " + ", ".join(v["formula"] for v in violations)
|
||||
if violations else "공허한 PASS 게이트 없음"
|
||||
),
|
||||
}
|
||||
save_json(str(TEMP / "vacuous_pass_audit_v1.json"), result)
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
return 0 if gate == "PASS" else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user