Files
QuantEngineByItz/tests/golden/generated/sell_waterfall_engine_v4_golden.py
kjh2064 aedabdd37b feat(quant-engine): v8.9 제안서 P0-P3 로드맵 채택 — 15개 의사결정 엔진 신규 구현
suggest/quant_investment_engine_v8_9_portfolio_optimizer_canonical_refactored.yaml의
implementation_todo_v8_9(P0~P4) 전체를 spec/tool/golden case 레벨로 구현.

- P0: PORTFOLIO_TRANSITION_UTILITY_V1, SELL_LOT_PARETO_SELECTOR_V1, FORECAST_SIMULATION_ENGINE_V1
- P1: SECTOR_EXPOSURE_GRAPH_V1/LEADER_LIFECYCLE_GATE_V1, EXECUTION_CAPACITY_LADDER_V1, MODEL_GOVERNANCE_KILL_SWITCH_V1
- P2: SCENARIO_SHOCK_MATRIX_V1, TRANSITION_SET_ENUMERATOR_V1, IMMUTABLE_DECISION_LEDGER_V1, EXECUTION_PLAN_COMPILER_V1
- P3: STATE_VECTOR_CONSTRUCTOR_V1, WALK_FORWARD_BOOTSTRAP_V1, TRANSITION_SET_ENUMERATOR_V1(MRC/CVaR 확장),
      REBALANCE_CADENCE_GATE_V1, WEEKLY_LEGACY_TRANSFER_PLAN_V1

기존 regime/cluster 연동 정책 수치(현금방어선, 반도체 cap)는 그대로 유지하고 신규 cap 필드만 추가.
spec/09_decision_flow.yaml과 runtime/active_artifact_manifest.yaml에 전 엔진 배선 완료.
governance/todo/v8_9_p{0,1,2,3}_adoption_plan.yaml에 각 단계 작업 추적 기록.

검증: validate_specs/validate_golden_coverage_100(100%)/validate_calibration_registry_v1/
validate_schema_model_generation_v1/validate_agents_shrink_v1 전부 PASS. golden test 53/53 PASS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 00:06:52 +09:00

54 lines
2.1 KiB
Python

"""Golden tests for SELL_LOT_PARETO_SELECTOR_V1 (governance/todo/v8_9_p0_adoption_plan.yaml P0-2.3).
Maps to v8.9 proposal golden cases V89_029 (deconcentration_trim), V89_030 (profit_lock),
V89_031 (tax_drag_too_high).
"""
from __future__ import annotations
import importlib.util
from pathlib import Path
ROOT = Path(__file__).resolve().parents[3]
MODULE_PATH = ROOT / "tools" / "build_sell_waterfall_engine_v4.py"
def _load_module():
spec = importlib.util.spec_from_file_location("build_sell_waterfall_engine_v4", MODULE_PATH)
module = importlib.util.module_from_spec(spec)
assert spec.loader is not None
spec.loader.exec_module(module)
return module
def test_v89_029_deconcentration_trim_dominates_lower_benefit_candidate() -> None:
mod = _load_module()
candidate_a = {"avoided_tail_loss_krw": 100000, "tax_fee_slippage_krw": 10000}
candidate_b = {"avoided_tail_loss_krw": 50000, "tax_fee_slippage_krw": 20000}
assert mod._dominates(candidate_a, candidate_b) is True
assert mod._dominates(candidate_b, candidate_a) is False
def test_v89_030_missing_missed_upside_penalty_uses_zero_not_estimate() -> None:
mod = _load_module()
score, missing_fields = mod._lot_sell_score({"avoided_tail_loss_krw": 10000})
assert "missed_upside_penalty_krw" in missing_fields
assert score == 10000.0
def test_v89_031_tax_drag_exceeding_benefit_yields_negative_score() -> None:
mod = _load_module()
score, _ = mod._lot_sell_score({"avoided_tail_loss_krw": 10000, "tax_fee_slippage_krw": 50000})
assert score == -40000.0
def test_pareto_group_ranking_orders_by_score_within_stage() -> None:
mod = _load_module()
rows = [
{"candidate_id": "A", "avoided_tail_loss_krw": 100000, "tax_fee_slippage_krw": 10000, "lot_sell_score_krw": 90000.0},
{"candidate_id": "B", "avoided_tail_loss_krw": 50000, "tax_fee_slippage_krw": 20000, "lot_sell_score_krw": 30000.0},
]
ranked = mod._rank_pareto_group(rows)
assert ranked[0]["candidate_id"] == "A"
assert ranked[0]["pareto_rank"] == 1
assert ranked[1]["pareto_dominated"] is True