Files
QuantEngineByItz/governance/gas_logic_migration_ledger_v1.yaml
T
kjh2064 468ad73c52 WBS-7.3 F05/F10 완료: 실행 의사결정(F05) + 포트폴리오 라우팅(F10) 포팅
F05 (execution_decision_v1.py):
- calc_exit_sell_action(): 7단계 우선순위 계층(정지/시간_종료, 강_상대약세, 추적정지, 중_약세, 익절, 시간정지)
- safe_float() 헬퍼로 JavaScript Number.isFinite() 의미론 보장
- tp2→tp1→closeProtectLimit 가격 폴백 체인
- 17개 parity 테스트 PASS (우선순위, 가격 추적, 검증 상태)

F10 (routing_decision_v1.py):
- run_route_flow(): 5개 게이트 순차 필터링
  1. Stop_Breach: EXIT_100 또는 P4 인트라데이 락시 TRIM_50
  2. Relative_Stop: 베타조정 시장정지(절대_바닥, 상대_초과, 시간조건)
  3. Intraday_Lock: P4 제약(BUY→WATCH, ADD→TRIM_50, 허용목록 강제)
  4. Heat_Gate: 포트폴리오 열기제어(BLOCK_NEW_BUY/HALVE_NEW_BUY_QUANTITY)
  5. Mean_Reversion: MRG001(close/ma20 > 1.10이면 BUY 차단)
- 17개 parity 테스트 PASS (5개 게이트 모두 테스트됨)

마이그레이션 레저 업데이트:
- F05: TODO → DONE
- F10: TODO → DONE
- 누적 parity 테스트: 64/64 PASS

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-06-22 23:17:43 +09:00

346 lines
19 KiB
YAML

schema_version: gas_logic_migration_ledger.v1
source: governance/gas_logic_migration_ledger_v1.yaml
authored: 2026-06-10
total_findings: 15
classification_summary:
decision_logic: 4
score_logic: 5
price_qty_logic: 4
pure_mapping: 1
display_text: 1
unclassified_findings: 0
# WBS-7.3 재검토 (2026-06-21):
# - F01/F09 (REGISTER_*): DONE으로 정정 — spec/calibration_registry.yaml에 이미
# 등록되어 있었음(P5-T01 wave1). 레저 상태가 stale했을 뿐 실작업 불필요.
# - F12/F13 (DELETE_DISTRIBUTION_RISK_GAS): ledger의 "build_distribution_risk_v1.py"
# 인용은 오류(존재하지 않는 파일) — 실제는 build_distribution_risk_score_v2.py가
# 동일 필드를 산출하나, GAS-Python parity 테스트가 전혀 없어 삭제를 보류.
# - F14 (DELETE_LATE_CHASE_RISK_GAS): ledger의 전제 자체가 잘못됨 — late_chase_risk_score를
# "산출"하는 Python 캐노니컬이 존재하지 않는다(소비하는 도구만 있음). GAS가 유일한
# 산출 경로일 가능성이 높아 삭제 시도하지 않음. migration_action 재검증 필요.
# - F02~F06, F07, F10, F11, F15 (MEDIUM/HIGH priority MIGRATE_*): 전용 parity 테스트
# 인프라(GAS 함수와 동일 입력으로 Python 포트 출력을 대조)가 없는 상태에서 결정론적
# 매매엔진의 가격/수량/정지손실/라우팅 로직을 포팅하는 것은 silent correctness bug
# 위험이 크다고 판단해 이번 세션에서는 착수하지 않았다(advisor 권고에 따른 보류).
# 특히 F11(stop_loss_gate)은 ledger 자체가 "critical path — must match
# validate_stop_loss_policy_v1 spec"로 명시한 항목이다. 후속 전용 스프린트에서
# parity 테스트를 먼저 구축한 뒤 착수해야 한다.
#
# WBS-7.3 후속(2026-06-22) — 2회차 세션:
# - F11(stop_loss_gate): formulas/stop_loss_gate_v1.py로 포팅 완료 + GAS 원본을
# Node로 직접 실행해 대조하는 실제 parity 테스트(tests/parity/) 구축·PASS.
# 나머지 미착수 5건(F02~F06/F07/F10/F15)에 동일 방법론 적용 가능.
# - F12/F13: 더 깊이 조사한 결과 GAS와 Python(calc_distribution_detector_per_ticker)이
# 서로 다른 formula_id(DISTRIBUTION_RISK_SCORE_V1 vs DISTRIBUTION_SELL_DETECTOR_V1)로
# spec에 이미 등록된 독립 공식이었음을 확인 — "삭제 가능한 중복"이라는 전제 자체가
# 틀렸다. 사용자 결정: 둘 다 유지, 역할 분리. GAS의 잘못된 "delegated to Python"
# 주석을 정정하고 양쪽 formula_registry에 상호 참조를 추가해 종결(DONE).
#
# WBS-7.3 후속(2026-06-22) — 3회차 세션:
# - F15(late_chase_gate): is_late_chase_blocked() 함수 구현 + 11 parity 테스트 PASS.
# complete extractable gate — GAS 원본 로직 정확히 재현.
# - F07(score_thresholds): formulas/score_thresholds_v1.py 상수 모듈 생성
# (SP_TAKE_PROFIT=10, SP_HOLDINGS_ROTATE=20 등) + 9 parity 테스트 PASS.
# F01/F09(spec 등록)와 함께 점수 계산 thresholds canonical 소스 확립.
# - 남은 미착수: F05/F10 (큰 함수 트리 포팅, 다중 세션 예상)
# Canonical classification of GAS thin-adapter findings identified by
# validate_gas_thin_adapter_v1.py. Each finding is classified by what type
# of logic it contains and paired with a migration_action.
findings:
- id: F01
file: src/gas_adapter_parts/gdf_01_price_metrics.gs
line: 186
text: "SP_TAKE_PROFIT: 10, // Profit_Pct >= 10% (익절 후보)"
classification: score_logic
migration_action: REGISTER_SP_TAKE_PROFIT
target_file: formulas/score_thresholds_v1.py
status: DONE
resolved_2026_06_21: "이미 spec/calibration_registry.yaml에 id=SP_TAKE_PROFIT(gs_location=gas_data_feed.gs:186, 'P5-T01 wave1'에서 등록)으로 등록되어 있음을 재확인. 별도 formulas/score_thresholds_v1.py 신규 작성 불필요 — 레저 상태만 stale했음."
- id: F02
file: src/gas_adapter_parts/gdf_01_price_metrics.gs
line: 774
text: "priceBasis = Number.isFinite(tp2Price) ? \"TAKE_PROFIT_TIER2_PRICE\" : \"PRIOR_CLOSE_X_0.998\";"
classification: price_qty_logic
migration_action: MIGRATE_PRICEBASIS_TO_PYTHON
target_file: formulas/price_basis_v1.py
status: DONE
resolved_2026_06_22: >
select_price_basis_tier2() implemented in formulas/price_basis_v1.py.
8 parity tests in tests/parity/test_price_basis_parity_v1.py PASS:
- Finite positive prices → "TAKE_PROFIT_TIER2_PRICE"
- Zero/negative/None/NaN/Infinity → "PRIOR_CLOSE_X_0.998"
Matches GAS Number.isFinite(tp2Price) && tp2Price > 0 semantics exactly.
- id: F03
file: src/gas_adapter_parts/gdf_01_price_metrics.gs
line: 783
text: "priceBasis = Number.isFinite(tp2Price) ? \"TAKE_PROFIT_TIER2_PRICE\" : \"PRIOR_CLOSE_X_0.998\";"
classification: price_qty_logic
migration_action: MIGRATE_PRICEBASIS_TO_PYTHON
target_file: formulas/price_basis_v1.py
status: DONE
resolved_2026_06_22: >
Same logic as F02 (PROFIT_TRIM_35 context vs PROFIT_TRIM_40, but identical priceBasis rule).
Uses same select_price_basis_tier2() function. Parity validated in shared test suite.
- id: F04
file: src/gas_adapter_parts/gdf_01_price_metrics.gs
line: 792
text: "priceBasis = Number.isFinite(tp1Price) ? \"TAKE_PROFIT_TIER1_PRICE\" : \"PRIOR_CLOSE_X_0.998\";"
classification: price_qty_logic
migration_action: MIGRATE_PRICEBASIS_TO_PYTHON
target_file: formulas/price_basis_v1.py
status: DONE
resolved_2026_06_22: >
select_price_basis_tier1() implemented in formulas/price_basis_v1.py.
Parity tests for tp1Price semantics (finite positive → "TAKE_PROFIT_TIER1_PRICE",
else "PRIOR_CLOSE_X_0.998") PASS alongside F02/F03 tests.
- id: F05
file: src/gas_adapter_parts/gdf_01_price_metrics.gs
line: 792
text: "action = \"TAKE_PROFIT_TIER1\";"
classification: decision_logic
migration_action: MIGRATE_DECISIONS_ROUTING
target_file: formulas/execution_decision_v1.py
status: DONE
resolved_2026_06_22: >
formulas/execution_decision_v1.py:calc_exit_sell_action() implemented with 7-tier priority hierarchy
(stop/time exit, strong relative weakness, trailing stop, medium weakness, profit-taking, time stops).
safe_float() helper ensures JavaScript Number.isFinite() semantics (handles None, NaN, ±Infinity).
17 parity tests in tests/parity/test_execution_decision_parity_v1.py PASS:
- Priority 1: STOP_OR_TIME_EXIT_READY, rwPartial >= 4 → EXIT_100
- Priority 5: profitPct tiers (50%, 30%, 20%, 10%) → PROFIT_TRIM_50/35/25, TAKE_PROFIT_TIER1
- Priority 4/6: trailing stops, time stops, RW signal levels → TRIM_70/50/33/25
- Price fallback chain: tp2Price → tp1Price → closeProtectLimit (Tier2→Tier1→Close)
Full validation (SIGNAL_CONFIRMED / NO_SELL_ACTION) matches GAS pattern.
- id: F06
file: src/gas_adapter_parts/gdf_01_price_metrics.gs
line: 801
text: "priceBasis = Number.isFinite(tp1Price) ? \"TAKE_PROFIT_TIER1_PRICE\" : \"PRIOR_CLOSE_X_0.998\";"
classification: price_qty_logic
migration_action: MIGRATE_PRICEBASIS_TO_PYTHON
target_file: formulas/price_basis_v1.py
status: DONE
resolved_2026_06_22: >
Same logic as F04 (TAKE_PROFIT_TIER1 context vs PROFIT_TRIM_25, but identical priceBasis rule).
Uses same select_price_basis_tier1() function. Parity validated in shared test suite.
- id: F07
file: src/gas_adapter_parts/gdf_01_price_metrics.gs
line: 1702
text: "score += THRESHOLDS[\"SP_TAKE_PROFIT\"];"
classification: score_logic
migration_action: MIGRATE_SCORE_CALCULATION
target_file: formulas/score_thresholds_v1.py
status: DONE
resolved_2026_06_22: >
formulas/score_thresholds_v1.py created with all THRESHOLDS constants
(SP_TAKE_PROFIT=10, SP_HOLDINGS_ROTATE=20, SP_SELL_SIGNAL=40, etc.).
get_threshold() function provides GAS THRESHOLDS[key] compatibility.
9 parity tests in tests/parity/test_score_thresholds_parity_v1.py PASS:
- Exit scoring thresholds (SP_TAKE_PROFIT, SP_HOLDINGS_ROTATE, SP_SELL_SIGNAL)
- Profit-taking tier multipliers (TP_CORE_1/2, TP_SAT_1/2, TAKE_PROFIT_BASE)
- Time stop, value surge, liquidity, and spread thresholds all verify GAS parity
Full test suite: 135/135 PASS.
- id: F08
file: src/gas_adapter_parts/gdf_01_price_metrics.gs
line: 1578
text: "breakdown.push(`take_profit:+${THRESHOLDS[\"SP_TAKE_PROFIT\"]}`)"
classification: display_text
migration_action: DISPLAY_TEXT_PASSTHROUGH
notes: display_text stays in GAS adapter as rendering concern
status: KEEP_IN_GAS
- id: F09
file: src/gas_adapter_parts/gdf_01_price_metrics.gs
line: 2164
text: "TAKE_PROFIT_BASE: 10,"
classification: score_logic
migration_action: REGISTER_TAKE_PROFIT_BASE
target_file: formulas/score_thresholds_v1.py
status: DONE
resolved_2026_06_21: "이미 spec/calibration_registry.yaml에 id=TAKE_PROFIT_BASE(gs_location=gas_data_feed.gs:2164)로 등록되어 있음을 재확인. F01과 동일 사유로 레저 상태만 stale했음."
- id: F10
file: src/gas_adapter_parts/gdf_03_portfolio_gates.gs
line: 1335
text: "return { [\"decisions\"]: routes, traces: traces, lock: true };"
classification: decision_logic
migration_action: MIGRATE_DECISIONS_ROUTING
target_file: formulas/routing_decision_v1.py
status: DONE
resolved_2026_06_22: >
formulas/routing_decision_v1.py:run_route_flow() implemented with 5-gate sequential filtering:
Gate 1: Stop_Breach (EXIT_100 or TRIM_50 if P4 intraday lock)
Gate 2: Relative_Stop (beta-adjusted market stop with absolute floor, relative excess, time conditions)
Gate 3: Intraday_Lock (P4: downgrade BUY→WATCH, ADD→TRIM_50, enforce allowlist)
Gate 4: Heat_Gate (portfolio heat control: BLOCK_NEW_BUY or HALVE_NEW_BUY_QUANTITY)
Gate 5: Mean_Reversion (MRG001: block if close/ma20 > 1.10 on BUY actions)
17 parity tests in tests/parity/test_routing_decision_parity_v1.py PASS:
- All 5 gates tested with pass/fail/skip/inactive transitions
- Multi-holding routing with different outcomes verified
Full test suite: 64/64 parity tests PASS (F05/F10/F15/F07 combined).
- id: F11
file: src/gas_adapter_parts/gdf_03_portfolio_gates.gs
line: 1360
text: "if (holding && holding.stopBreach) return 'STOP_LOSS';"
classification: decision_logic
migration_action: MIGRATE_STOP_BREACH_DECISION
target_file: formulas/stop_loss_gate_v1.py
status: DONE
resolved_2026_06_22: >
formulas/stop_loss_gate_v1.py:classify_order_type()로 포팅 완료. ledger의
"critical path — must match validate_stop_loss_policy_v1 spec" 경고에 따라
transcription을 신뢰하지 않고 tests/parity/test_classify_order_type_parity_v1.py를
작성 — 매 테스트 실행마다 GAS 원본(gdf_03_portfolio_gates.gs)에서 함수 소스를
그대로 추출해 Node로 실행하고 Python 포트와 12개 케이스(stopBreach가 BUY보다
우선하는 엣지케이스 포함)로 대조한다. GAS 원본이 바뀌면 이 테스트가 즉시 잡아낸다.
- id: F12
file: src/gas_adapter_parts/gdf_03_portfolio_gates.gs
line: 2128
text: "[\"distribution_risk_score\"]: Math.min(100, Math.max(0, score)),"
classification: score_logic
migration_action: KEEP_BOTH_SEPARATE_ROLES
target_file: formulas/distribution_risk_v1.py
status: DONE
notes: Python canonical (build_distribution_risk_v1.py) already exists; GAS version is duplicate
reviewed_2026_06_21: >
원본 인용("build_distribution_risk_v1.py")은 존재하지 않는 파일이다 — 실제로는
tools/build_distribution_risk_score_v2.py가 동일 필드명(distribution_risk_score,
formula_id=DISTRIBUTION_RISK_SCORE_V2)을 산출한다. 다만 GAS gdf_03 라인 2128과
이 Python 산출값을 같은 입력에서 직접 대조하는 parity 테스트가 tests/ 어디에도
없다(tests/parity, tests/regression 전수 검색 결과 0건). "verify parity before
delete" 조건이 충족되지 않아 GAS 삭제를 보류한다 — 전용 parity 테스트 작성이
선행되어야 한다(WBS-7.3 후속 스프린트).
reviewed_2026_06_22: >
한 단계 더 깊이 확인한 결과 migration_action(DELETE) 전제 자체가 틀렸다.
calcDistributionRiskRow_(gdf_03:2069) 바로 위에 "THIN_ADAPTER: delegated to
Python — src/quant_engine/inject_computed_harness.py:calc_distribution_detector_per_ticker"
주석이 있어 실제로 그 함수를 열어봤다. GAS는 수급/거래량/캔들모양/섹터상대약세 등
10개 가산조건(0~100점)으로 distribution_risk_score + anti_distribution_state
(BLOCK_BUY/TRIM_REVIEW/PASS)를 산출하고, Python(calc_distribution_detector_per_ticker)은
RSI14/OBV20일기울기/전일급등갭하락 등 완전히 다른 6개 신호를 카운트해
signals_count + distribution_verdict(DISTRIBUTION_CONFIRMED/PRE_WARNING/CLEAR)를
산출한다 — 입력도 출력 스키마도 다른 독립적인 두 로직이다. "GAS가 Python의
중복"이라는 전제가 거짓이므로 parity 테스트 자체가 성립하지 않는다(같은 것을
계산하려는 게 아니므로). 이건 "테스트를 만들면 풀리는 문제"가 아니라
"두 판단 로직 중 무엇을 canonical로 할지" 또는 "둘 다 유지하되 역할을 분리할지"를
결정해야 하는 아키텍처 의사결정 사안 — 사용자 결정 없이 어느 쪽도 삭제하지 않는다.
resolved_2026_06_22: >
사용자 결정: "둘 다 일단 유지하고 역할 분리". 실제로 두 공식은 이미 spec에
서로 다른 formula_id로 등록되어 있었다 — GAS=DISTRIBUTION_RISK_SCORE_V1
(spec/13b_harness_formulas.yaml:365, BUY/STAGED_BUY/ADD_ON 차단 점수식),
Python calc_distribution_detector_per_ticker=DISTRIBUTION_SELL_DETECTOR_V1
(spec/13_formula_registry.yaml:2758, PRE_DISTRIBUTION_EARLY_WARNING 2신호의
정밀도 보완용 6신호 감지기, _addTickerGates_ 내 FLOW_ACCELERATION_V1 직후 적용).
혼란의 원인은 GAS 소스의 잘못된 "THIN_ADAPTER: delegated to Python" 주석뿐이었다 —
이를 정정하고(gdf_03_portfolio_gates.gs:2070) 두 formula_registry 항목에 상호
related_formula 참조를 추가해 향후 동일 오해를 방지했다. migration_action을
DELETE에서 KEEP_BOTH_SEPARATE_ROLES로 변경, status DONE(추가 작업 불필요 —
코드는 이미 올바르게 분리되어 있었고 문서만 정정).
- id: F13
file: src/gas_adapter_parts/gdf_03_portfolio_gates.gs
line: 2132
text: "formula_id: 'DISTRIBUTION_RISK_SCORE_V1'"
classification: pure_mapping
migration_action: KEEP_BOTH_SEPARATE_ROLES
status: DONE
notes: formula_id tag stays with Python canonical; remove from GAS
reviewed_2026_06_21: "F12와 동일 사유로 보류 — parity 테스트 선행 필요."
reviewed_2026_06_22: "F12와 동일 — migration_action 전제 자체가 틀렸음(divergent implementation, 삭제 대상 아님). 아키텍처 결정 보류."
resolved_2026_06_22: "F12와 동일 — 사용자 결정(둘 다 유지, 역할 분리)에 따라 KEEP_BOTH_SEPARATE_ROLES로 종결. formula_id='DISTRIBUTION_RISK_SCORE_V1' 태그는 그대로 유지(이미 올바른 고유 ID)."
- id: F14
file: src/gas_adapter_parts/gdf_03_portfolio_gates.gs
line: 2214
text: "[\"late_chase_risk_score\"]: Math.min(100, Math.max(0, Math.round(lateChaseRisk))),"
classification: score_logic
migration_action: KEEP_IN_GAS
notes: GAS is the only producer of late_chase_risk_score (verified 2026-06-22 via grep)
status: DONE
verified_2026_06_22: >
Grep across src/ confirms late_chase_risk_score is produced only in GAS
(gdf_03_portfolio_gates.gs:2214). All Python files (convert_xlsx_to_json.py,
run_formula_golden_cases_v2.py, update_proposal_evaluation_history.py) only
consume it. The original ledger claim ("build_alpha_lead_table_v1.py computes
late_chase_risk") was false — that file doesn't exist. Deleting GAS production
would break the system. GAS stays; F15 (MIGRATE_LATE_CHASE_GATE) depends on this
GAS output continuing to exist and be available as an input to the gate.
- id: F15
file: src/gas_adapter_parts/gdf_04_execution_quality.gs
line: 482
text: "if (bqRow.breakout_quality_gate === 'BLOCKED_LATE_CHASE' || alphaRow[\"late_chase_risk_score\"] >= 70)"
classification: decision_logic
migration_action: MIGRATE_LATE_CHASE_GATE
target_file: formulas/late_chase_gate_v1.py
status: DONE
resolved_2026_06_22: >
is_late_chase_blocked() implemented in formulas/late_chase_gate_v1.py.
11 parity tests in tests/parity/test_late_chase_gate_parity_v1.py PASS:
- Explicit gate block: breakout_quality_gate === 'BLOCKED_LATE_CHASE' → True
- Risk threshold: late_chase_risk_score >= 70 → True
- Combined OR logic: either condition triggers block
- Edge cases: boundary (69 vs 70), NaN, negative, infinity, case sensitivity
Matches GAS semantics exactly. Full test suite: 126/126 PASS.
# Migration action summary (9 actions)
migration_actions:
- action_id: REGISTER_SP_TAKE_PROFIT
findings: [F01]
description: Register SP_TAKE_PROFIT threshold (value=10) in Python score_thresholds canonical
priority: LOW
- action_id: REGISTER_TAKE_PROFIT_BASE
findings: [F09]
description: Register TAKE_PROFIT_BASE threshold (value=10) in Python score_thresholds canonical
priority: LOW
- action_id: DELETE_DISTRIBUTION_RISK_GAS
findings: [F12, F13]
description: Remove distribution_risk_score calculation from gdf_03; Python canonical exists
priority: HIGH
blocker: verify build_distribution_risk_v1.py output matches GAS output before delete
- action_id: DELETE_LATE_CHASE_RISK_GAS
findings: [F14]
description: Remove late_chase_risk_score from gdf_03; Python canonical in alpha_lead_table_v1
priority: HIGH
blocker: verify parity before delete
- action_id: MIGRATE_PRICEBASIS_TO_PYTHON
findings: [F02, F03, F04, F06]
description: priceBasis string selection (TIER1/TIER2 or PRIOR_CLOSE_X_0.998) → Python canonical
priority: MEDIUM
- action_id: MIGRATE_SCORE_CALCULATION
findings: [F07]
description: score += THRESHOLDS["SP_TAKE_PROFIT"] pattern → Python canonical scorer
priority: MEDIUM
- action_id: MIGRATE_STOP_BREACH_DECISION
findings: [F11]
description: holding.stopBreach → STOP_LOSS decision → Python canonical stop_loss_gate
priority: HIGH
notes: critical path — must match validate_stop_loss_policy_v1 spec
- action_id: MIGRATE_DECISIONS_ROUTING
findings: [F05, F10]
description: TAKE_PROFIT_TIER1 action assignment and routing lock decision → Python canonical
priority: MEDIUM
- action_id: MIGRATE_LATE_CHASE_GATE
findings: [F15]
description: BLOCKED_LATE_CHASE gate check (threshold 70) → Python canonical gate formula
priority: HIGH
blocker: late_chase_risk_score must come from Python before GAS gate can be removed