From c8a2c36bfb7869254452f9d4c6cdee740219ffdc Mon Sep 17 00:00:00 2001 From: 21in7 Date: Mon, 2 Mar 2026 19:47:18 +0900 Subject: [PATCH] feat: add ADX calculation to indicators Add ADX (Average Directional Index) with period 14 to calculate_all() for sideways market filtering. Includes test verifying the adx column exists and contains non-negative values. Co-Authored-By: Claude Opus 4.6 --- src/indicators.py | 4 ++++ tests/test_indicators.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/indicators.py b/src/indicators.py index 882d87e..5a2f166 100644 --- a/src/indicators.py +++ b/src/indicators.py @@ -43,6 +43,10 @@ class Indicators: df["stoch_k"] = stoch["STOCHRSIk_14_14_3_3"] df["stoch_d"] = stoch["STOCHRSId_14_14_3_3"] + # ADX (14) — 횡보장 필터 + adx_df = ta.adx(df["high"], df["low"], df["close"], length=14) + df["adx"] = adx_df["ADX_14"] + # 거래량 이동평균 df["vol_ma20"] = ta.sma(df["volume"], length=20) diff --git a/tests/test_indicators.py b/tests/test_indicators.py index 2a10be9..9d20fbd 100644 --- a/tests/test_indicators.py +++ b/tests/test_indicators.py @@ -45,6 +45,15 @@ def test_bollinger_bands(sample_df): assert (valid["bb_upper"] >= valid["bb_lower"]).all() +def test_adx_column_exists(sample_df): + """calculate_all()이 adx 컬럼을 생성하는지 확인.""" + ind = Indicators(sample_df) + df = ind.calculate_all() + assert "adx" in df.columns + valid = df["adx"].dropna() + assert (valid >= 0).all() + + def test_signal_returns_direction(sample_df): ind = Indicators(sample_df) df = ind.calculate_all()