]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
perf(qav3): improve reversal confirmation
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 4 May 2025 18:50:18 +0000 (20:50 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 4 May 2025 18:50:18 +0000 (20:50 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py
quickadapter/user_data/strategies/Utils.py

index b83f715f3154d2a72765a3d573ee45696166694e..cb01f4c1a6f89439716b785717ba4723d66fcddf 100644 (file)
@@ -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
index 615c21c923c9fda7b8967ae405ba657f5cef310e..30a054e9e103da638edc237e15404d81c6c2368f 100644 (file)
@@ -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