Files
kjh2064 af1236202d WBS-7.3: GAS→Python 마이그레이션 5개 항목 완료 (F14, F02-F06)
- F14: late_chase_risk_score 검증
  * GAS가 유일한 생산처 (Python canonical 없음)
  * migration_action: KEEP_IN_GAS로 정정, status: DONE

- F02/F03/F04/F06: priceBasis 로직 포팅
  * formulas/price_basis_v1.py: select_price_basis_tier2/tier1 구현
  * tests/parity/test_price_basis_parity_v1.py: 8 parity 테스트 (모두 PASS)
  * GAS Number.isFinite() 의미론 정확히 재현 (math.isfinite 사용)
  * 모든 테스트 112/112 PASS

남은 작업 (4개):
- F05: decision_logic (action assignment)
- F07: score_logic (threshold addition)
- F10: routing decision
- F15: late_chase_gate

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

41 lines
1.3 KiB
Python

"""
Price basis selection logic for exit sell actions.
F02/F03/F04/F06 porting: Determines the basis for price selection (e.g., take-profit tier
prices vs. close-based protective limits) in the sell signal decision tree.
Ported from: src/gas_adapter_parts/gdf_01_price_metrics.gs:calcExitSellAction_()
Parity reference: tests/parity/test_price_basis_parity_v1.py
"""
import math
def is_finite(value) -> bool:
"""JavaScript Number.isFinite() semantics: true only for finite numbers."""
return isinstance(value, (int, float)) and math.isfinite(value)
def select_price_basis_tier2(tp2_price: float) -> str:
"""
Select price basis for PROFIT_TRIM_40/35 actions (profitPct >= 40/30).
F02/F03: lines 774, 783
GAS: Number.isFinite(tp2Price) && tp2Price > 0 ? "TAKE_PROFIT_TIER2_PRICE" : "PRIOR_CLOSE_X_0.998"
"""
if is_finite(tp2_price) and tp2_price > 0:
return "TAKE_PROFIT_TIER2_PRICE"
return "PRIOR_CLOSE_X_0.998"
def select_price_basis_tier1(tp1_price: float) -> str:
"""
Select price basis for PROFIT_TRIM_25/TAKE_PROFIT_TIER1 actions (profitPct >= 20/10).
F04/F06: lines 792, 801
GAS: Number.isFinite(tp1Price) && tp1Price > 0 ? "TAKE_PROFIT_TIER1_PRICE" : "PRIOR_CLOSE_X_0.998"
"""
if is_finite(tp1_price) and tp1_price > 0:
return "TAKE_PROFIT_TIER1_PRICE"
return "PRIOR_CLOSE_X_0.998"