[STK2-04] 기술 지표 (indicators·momentum)

작업 내용 (설계 의도)

변경 사항

  • indicators.py: RSI14 (데이터<15 → None).
  • momentum.py: MA20 이격(±10%=±1)·MA5/MA20 크로스(±5%=±1, 데이터≥40)·RSI 정규화 평균, [-1,1] 클램핑.

의존

  • 선행: STK2-01
  • 후행: STK2-06

다이어그램

처리 흐름

sequenceDiagram
    participant SS as signal_service
    participant MO as momentum.py
    participant IN as indicators.py
    SS->>MO: score(closes)
    MO->>MO: MA20 이격 계산 (closes >= 20)
    alt closes >= 40
        MO->>MO: MA5/MA20 크로스 계산
    end
    alt closes >= 15
        MO->>IN: rsi(closes, period=14)
        IN-->>MO: rsi_value
        MO->>MO: RSI 정규화 ((rsi-50)/50)
    end
    MO->>MO: 가용 요소 평균 + clamp(-1,1)
    MO-->>SS: momentum_score: float

클래스 의존

flowchart LR
    subgraph Application["Application"]
        signal_service["signal_service.py"]
    end
    subgraph Domain["Domain"]
        momentum["momentum.py (score)"]
        indicators["indicators.py (rsi)"]
    end
    signal_service --> momentum
    momentum --> indicators

테스트 케이스

  • 데이터가 20개 미만이면 MA20 이격을 제외하고 가용 요소만으로 모멘텀을 계산한다.
  • 데이터가 40개 미만이면 MA5/MA20 크로스를 제외하고 계산한다.
  • 데이터가 15개 미만이면 RSI를 None으로 처리한다.
  • MA20 이격이 +10%(±0.10) 이면 정규화 점수가 +1.0이 된다.
  • 모든 요소가 유효할 때 3요소 평균이 [-1, 1] 범위로 클램핑된다.
  • 극단값 입력에도 클램핑 후 점수는 -1.0 이상 1.0 이하다.