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 <noreply@anthropic.com>
This commit is contained in:
21in7
2026-03-02 19:47:18 +09:00
parent b8b99da207
commit c8a2c36bfb
2 changed files with 13 additions and 0 deletions

View File

@@ -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)

View File

@@ -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()