aedabdd37b
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>
91 lines
3.2 KiB
Python
91 lines
3.2 KiB
Python
#!/usr/bin/env python3
|
|
"""REBALANCE_CADENCE_GATE_V1 — spec/formulas/domains/portfolio.yaml.
|
|
|
|
Mandatory weekly (Sat/Sun) and monthly (1/11/21) cadence checks always emit a
|
|
review, but actual rebalancing execution is allowed only when transition utility
|
|
after tax cost is positive or a hard risk block is active.
|
|
governance/todo/v8_9_p3_adoption_plan.yaml P3-D.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from datetime import date
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
DEFAULT_OUT = ROOT / "Temp" / "rebalance_cadence_gate_v1.json"
|
|
|
|
WEEKLY_WEEKDAYS = {5, 6} # Saturday=5, Sunday=6 (date.weekday())
|
|
MONTHLY_MID_CHECK_DAYS = {1, 11, 21}
|
|
|
|
|
|
def cadence_check_required(check_date: date, event_driven_trigger: bool = False) -> tuple[bool, str | None]:
|
|
if check_date.weekday() in WEEKLY_WEEKDAYS:
|
|
return True, "weekly_rebalance_required"
|
|
if check_date.day in MONTHLY_MID_CHECK_DAYS:
|
|
return True, "mid_check_required"
|
|
if event_driven_trigger:
|
|
return True, "event_driven_trigger"
|
|
return False, None
|
|
|
|
|
|
def evaluate_rebalance_gate(
|
|
check_date: date,
|
|
transition_utility_after_tax_cost_krw: float | None,
|
|
hard_risk_block_active: bool | None,
|
|
event_driven_trigger: bool = False,
|
|
) -> dict:
|
|
required, reason = cadence_check_required(check_date, event_driven_trigger)
|
|
if not required:
|
|
return {
|
|
"cadence_check_required": False,
|
|
"review_emitted": False,
|
|
"rebalance_execution_allowed": False,
|
|
"cadence_trigger_reason": None,
|
|
}
|
|
|
|
if transition_utility_after_tax_cost_krw is None and hard_risk_block_active is None:
|
|
return {
|
|
"cadence_check_required": True,
|
|
"review_emitted": True,
|
|
"rebalance_execution_allowed": False,
|
|
"cadence_trigger_reason": reason,
|
|
"gate": "DATA_MISSING",
|
|
}
|
|
|
|
allowed = bool(hard_risk_block_active) or (
|
|
transition_utility_after_tax_cost_krw is not None and transition_utility_after_tax_cost_krw > 0
|
|
)
|
|
return {
|
|
"cadence_check_required": True,
|
|
"review_emitted": True,
|
|
"rebalance_execution_allowed": allowed,
|
|
"cadence_trigger_reason": reason,
|
|
}
|
|
|
|
|
|
def main() -> int:
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--date", default=None, help="YYYY-MM-DD, default today")
|
|
ap.add_argument("--transition-utility", type=float, default=None)
|
|
ap.add_argument("--hard-risk-block", action="store_true")
|
|
ap.add_argument("--event-driven-trigger", action="store_true")
|
|
ap.add_argument("--out", default=str(DEFAULT_OUT))
|
|
args = ap.parse_args()
|
|
|
|
check_date = date.fromisoformat(args.date) if args.date else date.today()
|
|
result = {
|
|
"formula_id": "REBALANCE_CADENCE_GATE_V1",
|
|
**evaluate_rebalance_gate(check_date, args.transition_utility, args.hard_risk_block, args.event_driven_trigger),
|
|
"check_date": check_date.isoformat(),
|
|
}
|
|
out = Path(args.out)
|
|
out.write_text(json.dumps(result, ensure_ascii=False, indent=2), encoding="utf-8")
|
|
print(json.dumps(result, ensure_ascii=False, indent=2))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|