From: Jérôme Benoit Date: Sun, 4 May 2025 18:50:18 +0000 (+0200) Subject: perf(qav3): improve reversal confirmation X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3973f5648df6b35533213720d0ff7aba958594f8;p=freqai-strategies.git perf(qav3): improve reversal confirmation Signed-off-by: Jérôme Benoit --- 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