Files
QuantEngineByItz/src/quant_engine/auto_fill_velocity_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

93 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""
WBS-9.3: Velocity 자동 충전 절차
조건: velocity_1d IS NULL AND (close_price AND previous_close_price) IS NOT NULL
"""
def calculate_velocity_1d(close_price: float, previous_close: float) -> float:
"""
Calculate 1-day velocity (percentage change).
입력: close_price, previous_close
출력: velocity_1d (%, e.g., 2.5 = +2.5%)
"""
if previous_close is None or previous_close == 0:
return None
velocity = ((close_price - previous_close) / previous_close) * 100
return round(velocity, 2)
def calculate_velocity_5d(closes: list[float]) -> float:
"""
Calculate 5-day velocity (5-period momentum).
입력: close 가격 리스트 (최소 5개)
출력: velocity_5d (%, e.g., 5.2 = +5.2%)
"""
if not closes or len(closes) < 5:
return None
current = closes[-1]
five_days_ago = closes[-5]
if five_days_ago is None or five_days_ago == 0:
return None
velocity = ((current - five_days_ago) / five_days_ago) * 100
return round(velocity, 2)
def auto_fill_velocity_1d(row: dict) -> dict:
"""
자동 충전: velocity_1d 필드
입력:
row: 현재 행 (velocity_1d = None)
필수: close_price, previous_close_price
출력:
row (velocity_1d 채워짐) 또는 원본 (실패시)
"""
if row.get("velocity_1d") is not None:
return row
close = row.get("close_price")
prev_close = row.get("previous_close_price")
if close is None or prev_close is None:
return row
velocity_1d = calculate_velocity_1d(close, prev_close)
if velocity_1d is not None:
row["velocity_1d"] = velocity_1d
row["_fill_source"] = "auto_fill_velocity_v1"
return row
def auto_fill_velocity_5d(row: dict, historical_closes: list[float] = None) -> dict:
"""
자동 충전: velocity_5d 필드
입력:
row: 현재 행
historical_closes: 과거 close 가격 (최소 5일)
출력:
row (velocity_5d 채워짐) 또는 원본 (실패시)
"""
if row.get("velocity_5d") is not None:
return row
if not historical_closes:
return row
velocity_5d = calculate_velocity_5d(historical_closes)
if velocity_5d is not None:
row["velocity_5d"] = velocity_5d
row["_fill_source"] = "auto_fill_velocity_v1"
return row