Files
QuantEngineByItz/src/quant_engine/auto_fill_atr20_v1.py
T
kjh2064 3ec28e6e0b WBS-9: Phase 9 모든 항목 준비 완료 — 7개 도구 & 문서 완성
WBS-9.1: F14 마이그레이션 완결 
- late_chase_risk_score, late_chase_gate 포트 완료
- Parity 테스트 36개 PASS (17+19 테스트)
- docs/WBS_9_1_F14_MIGRATION_COMPLETE_2026_06_22.md

WBS-9.2: snapshot_admin 성능 최적화
- tools/benchmark_snapshot_admin_performance_v1.py
- 단일/동시 테이블 성능 측정
- P99 < 2초 검증, 자동 리포트 생성

WBS-9.3: 데이터 품질 강화  80% 완료
- spec/12_field_dictionary.yaml: NULL 정책 추가
- auto_fill_atr20_v1.py: ATR20 자동 계산
- auto_fill_rsi14_v1.py: RSI14 자동 계산
- auto_fill_velocity_v1.py: velocity 자동 계산
- auto_fill_stop_price_v1.py: 손절가 자동 계산
- CI 게이트 3개 (NULL_CHECK, FILLABLE, ESTIMATION_BLOCK)

WBS-9.4: 장애 대응 플레이북 
- docs/WBS_9_4_INCIDENT_RESPONSE_PLAYBOOK_2026_06_22.md
- 5가지 시나리오 (KIS, Cloudflare, GAS, Admin, Data)
- RTO/RPO 명시, 모의 훈련 일정

WBS-9.5: 섹터 플로우 신호 신뢰도
- tools/measure_sector_flow_reliability_v1.py
- Hit Rate, Correlation, Reliability Score 측정
- HIGH/MEDIUM/LOW/INSUFFICIENT 판정
- WBS-8.5 완료(섹터 플로우 30일) 후 실행

WBS-9.6: LLM 레이더 문서 최적화 전략
- docs/WBS_9_6_LLM_RADAR_OPTIMIZATION_STRATEGY_2026_06_22.md
- 5-Phase 구현 계획 (신뢰도/순서/의존성/용어/오류검증)
- 목표: 독해 오류율 50% 이상 감소

WBS-9.7: 자동 백업 & 복구
- tools/backup_recovery_manager_v1.py
- 일일 증분/주간 전체 백업
- 자동 정리(30일), 무결성 검증
- 복구 < 1시간, 99% 성공률 목표

WBS-9 최종 요약:
- docs/WBS_9_FINAL_SUMMARY_2026_06_22.md
- 7개 항목 모두 준비 완료
- 2026-08-01 공식 시작
- 14-21일 병렬 진행으로 완료 가능

파일 추가:
- src/quant_engine/auto_fill_atr20_v1.py
- src/quant_engine/auto_fill_rsi14_v1.py
- src/quant_engine/auto_fill_velocity_v1.py
- src/quant_engine/auto_fill_stop_price_v1.py
- tools/measure_sector_flow_reliability_v1.py
- tools/backup_recovery_manager_v1.py
- docs/WBS_9_FINAL_SUMMARY_2026_06_22.md

Next: WBS-8.1 (T+20 ledger 30건, ~2026-07-15)

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

60 lines
1.4 KiB
Python

#!/usr/bin/env python3
"""
WBS-9.3: ATR20 자동 충전 절차
조건: atr20 IS NULL AND close_price IS NOT NULL
"""
def calculate_atr20(closes: list[float], period: int = 20) -> float:
"""
Calculate ATR (Average True Range) for 20 days.
입력: close 가격 리스트 (최소 20일)
출력: ATR20 (숫자)
"""
if len(closes) < period:
return None
# True Range 계산 (간소화 버전: 현재 close 기반)
trs = []
for i in range(1, len(closes)):
high = closes[i]
low = closes[i]
prev_close = closes[i - 1]
tr = max(
high - low,
abs(high - prev_close),
abs(low - prev_close)
)
trs.append(tr)
if not trs:
return None
# ATR = SMA of True Range (20일)
atr = sum(trs[-period:]) / min(period, len(trs))
return round(atr, 2)
def auto_fill_atr20(row: dict, historical_closes: list[float] = None) -> dict:
"""
자동 충전: atr20 필드
입력:
row: 현재 행 (atr20 = None)
historical_closes: 과거 close 가격 (최소 20일)
출력:
row (atr20 채워짐) 또는 원본 (실패시)
"""
if not historical_closes or row.get("atr20") is not None:
return row
atr20 = calculate_atr20(historical_closes)
if atr20 is not None:
row["atr20"] = atr20
row["_fill_source"] = "auto_fill_atr20_v1"
return row