From 3973f5648df6b35533213720d0ff7aba958594f8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 4 May 2025 20:50:18 +0200 Subject: [PATCH] perf(qav3): improve reversal confirmation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../user_data/freqaimodels/QuickAdapterRegressorV3.py | 9 +++++---- quickadapter/user_data/strategies/Utils.py | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index b83f715..cb01f4c 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -850,7 +850,7 @@ def zigzag( df: pd.DataFrame, natr_period: int = 14, natr_ratio: float = 1.0, - confirmation_window: int = 2, + confirmation_window: int = 6, depth: int = 12, ) -> tuple[list[int], list[float], list[int]]: if df.empty or len(df) < natr_period + confirmation_window: @@ -860,6 +860,7 @@ def zigzag( thresholds = ( (ta.NATR(df, timeperiod=natr_period) * natr_ratio).fillna(method="bfill").values ) + closes = df["close"].values highs = df["high"].values lows = df["low"].values @@ -883,11 +884,11 @@ def zigzag( def is_reversal_confirmed(pos: int, direction: TrendDirection) -> bool: if pos + confirmation_window >= len(df): return False - next_closes = df["close"].values[pos + 1 : pos + confirmation_window + 1] + next_closes = closes[pos + 1 : pos + confirmation_window + 1] if direction == TrendDirection.DOWN: - return all(c < highs[pos] for c in next_closes) + return np.all(next_closes < highs[pos]) elif direction == TrendDirection.UP: - return all(c > lows[pos] for c in next_closes) + return np.all(next_closes > lows[pos]) return False start_pos = 0 diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index 615c21c..30a054e 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -339,7 +339,7 @@ def zigzag( df: pd.DataFrame, natr_period: int = 14, natr_ratio: float = 1.0, - confirmation_window: int = 2, + confirmation_window: int = 6, depth: int = 12, ) -> tuple[list[int], list[float], list[int]]: if df.empty or len(df) < natr_period + confirmation_window: @@ -349,6 +349,7 @@ def zigzag( thresholds = ( (ta.NATR(df, timeperiod=natr_period) * natr_ratio).fillna(method="bfill").values ) + closes = df["close"].values highs = df["high"].values lows = df["low"].values @@ -372,11 +373,11 @@ def zigzag( def is_reversal_confirmed(pos: int, direction: TrendDirection) -> bool: if pos + confirmation_window >= len(df): return False - next_closes = df["close"].values[pos + 1 : pos + confirmation_window + 1] + next_closes = closes[pos + 1 : pos + confirmation_window + 1] if direction == TrendDirection.DOWN: - return all(c < highs[pos] for c in next_closes) + return np.all(next_closes < highs[pos]) elif direction == TrendDirection.UP: - return all(c > lows[pos] for c in next_closes) + return np.all(next_closes > lows[pos]) return False start_pos = 0 -- 2.43.0