Files
kis_bot/kis_trader/engine/atr_series.py
Hwang ad0ad308d1 fix: Refactor imports and remove unused ATR calculation
Changes:
- Updated import paths for `compute_atr_series` and `is_strategy_eod_bar` to reflect new module structure.
- Removed the unused `compute_atr_series` function from `tail_engine.py`, streamlining the codebase.

Impact:
- These changes enhance code organization and maintainability by ensuring that only necessary components are imported and utilized, while also eliminating redundant code.
2026-07-06 20:27:39 +09:00

38 lines
1.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""
kis_trader/engine/atr_series.py — ATR 시리즈 (엔진·전략 공통, 순환 import 방지)
"""
from __future__ import annotations
from typing import Dict, List, Optional
def compute_atr_series(candles: List[Dict], period: int = 14) -> List[Optional[float]]:
"""
ATR(Average True Range) 변동성 지표 계산기 (엔진 내부용).
■ RMA(Wilder's Smoothing) 방식 — TradingView 기본과 동일 (2026-06 SMA→RMA 전환).
ATR_t = (ATR_{t-1} × (period-1) + TR_t) / period
· 첫 ATR(인덱스 period)은 SMA(TR[1..period])로 시드.
· SMA 대비: 급락(큰 TR)이 14봉 지나도 '계단식 급락' 없이 완만히 감쇠 →
급변장에서 손절/목표가가 덜 출렁임.
"""
atr_list: List[Optional[float]] = [None] * len(candles)
if len(candles) < period + 1:
return atr_list
trs = [0.0] * len(candles)
for i in range(1, len(candles)):
hi = float(candles[i]["high"])
lo = float(candles[i]["low"])
prev_cl = float(candles[i - 1]["close"])
trs[i] = max(hi - lo, abs(hi - prev_cl), abs(lo - prev_cl))
# 첫 ATR(인덱스 period): TR[1..period] 단순 평균으로 시드 (Wilder 초기값)
prev_atr = sum(trs[1:period + 1]) / period
atr_list[period] = prev_atr
# 이후: Wilder RMA 누적 감쇠 (이전 ATR×(n-1) + 오늘 TR) / n
for i in range(period + 1, len(candles)):
prev_atr = (prev_atr * (period - 1) + trs[i]) / period
atr_list[i] = prev_atr
return atr_list