]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
fix(qav3): avoid log usage on values that can be close to zero
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 19 May 2025 09:22:07 +0000 (11:22 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Mon, 19 May 2025 09:22:07 +0000 (11:22 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py
quickadapter/user_data/strategies/QuickAdapterV3.py
quickadapter/user_data/strategies/Utils.py

index ba3d4a534529405687385835f46cbd314efeaeb7..12f765c7472c489e145240ff1e6d288435644131 100644 (file)
@@ -851,7 +851,7 @@ class TrendDirection(IntEnum):
 def zigzag(
     df: pd.DataFrame,
     natr_period: int = 14,
-    natr_ratio: float = 1.0,
+    natr_ratio: float = 0.12125,
     confirmation_window: int = 3,
     initial_depth: int = 12,
 ) -> tuple[list[int], list[float], list[int]]:
@@ -1042,16 +1042,16 @@ def zigzag(
         significant_move_away_ok = False
         if direction == TrendDirection.DOWN:
             if np.any(
-                np.log(next_lows)
-                < np.log(highs[candidate_pivot_pos])
-                + np.log(1 - thresholds[candidate_pivot_pos] * move_away_ratio)
+                next_lows
+                < highs[candidate_pivot_pos]
+                (1 - thresholds[candidate_pivot_pos] * move_away_ratio)
             ):
                 significant_move_away_ok = True
         elif direction == TrendDirection.UP:
             if np.any(
-                np.log(next_highs)
-                > np.log(lows[candidate_pivot_pos])
-                + np.log(1 + thresholds[candidate_pivot_pos] * move_away_ratio)
+                next_highs
+                > lows[candidate_pivot_pos]
+                (1 + thresholds[candidate_pivot_pos] * move_away_ratio)
             ):
                 significant_move_away_ok = True
         return significant_move_away_ok
@@ -1071,10 +1071,13 @@ def zigzag(
 
         initial_move_from_high = (initial_high - current_low) / initial_high
         initial_move_from_low = (current_high - initial_low) / initial_low
-        if (
+        is_initial_high_move_significant = (
             initial_move_from_high >= thresholds[initial_high_pos]
-            and initial_move_from_low >= thresholds[initial_low_pos]
-        ):
+        )
+        is_initial_low_move_significant = (
+            initial_move_from_low >= thresholds[initial_low_pos]
+        )
+        if is_initial_high_move_significant and is_initial_low_move_significant:
             if initial_move_from_high > initial_move_from_low:
                 if is_reversal_confirmed(
                     initial_high_pos, initial_high_pos, TrendDirection.DOWN
@@ -1090,17 +1093,13 @@ def zigzag(
                     state = TrendDirection.UP
                     break
         else:
-            if initial_move_from_high >= thresholds[
-                initial_high_pos
-            ] and is_reversal_confirmed(
+            if is_initial_high_move_significant and is_reversal_confirmed(
                 initial_high_pos, initial_high_pos, TrendDirection.DOWN
             ):
                 add_pivot(initial_high_pos, initial_high, TrendDirection.UP)
                 state = TrendDirection.DOWN
                 break
-            elif initial_move_from_low >= thresholds[
-                initial_low_pos
-            ] and is_reversal_confirmed(
+            elif is_initial_low_move_significant and is_reversal_confirmed(
                 initial_low_pos, initial_low_pos, TrendDirection.UP
             ):
                 add_pivot(initial_low_pos, initial_low, TrendDirection.DOWN)
index d86d17e9d91957b108e3353ec6006d6bb33b607f..0b203fefe4f6857ccaad2c6a6582aeda8d47b891 100644 (file)
@@ -58,7 +58,7 @@ class QuickAdapterV3(IStrategy):
     INTERFACE_VERSION = 3
 
     def version(self) -> str:
-        return "3.3.39"
+        return "3.3.40"
 
     timeframe = "5m"
 
index 440edcd266760df744feffc923858bb28244b223..eb47cc1542a1941a969c9be0dae6c8ae05e7753b 100644 (file)
@@ -348,7 +348,7 @@ class TrendDirection(IntEnum):
 def zigzag(
     df: pd.DataFrame,
     natr_period: int = 14,
-    natr_ratio: float = 1.0,
+    natr_ratio: float = 0.12125,
     confirmation_window: int = 3,
     initial_depth: int = 12,
 ) -> tuple[list[int], list[float], list[int]]:
@@ -539,16 +539,16 @@ def zigzag(
         significant_move_away_ok = False
         if direction == TrendDirection.DOWN:
             if np.any(
-                np.log(next_lows)
-                < np.log(highs[candidate_pivot_pos])
-                + np.log(1 - thresholds[candidate_pivot_pos] * move_away_ratio)
+                next_lows
+                < highs[candidate_pivot_pos]
+                (1 - thresholds[candidate_pivot_pos] * move_away_ratio)
             ):
                 significant_move_away_ok = True
         elif direction == TrendDirection.UP:
             if np.any(
-                np.log(next_highs)
-                > np.log(lows[candidate_pivot_pos])
-                + np.log(1 + thresholds[candidate_pivot_pos] * move_away_ratio)
+                next_highs
+                > lows[candidate_pivot_pos]
+                (1 + thresholds[candidate_pivot_pos] * move_away_ratio)
             ):
                 significant_move_away_ok = True
         return significant_move_away_ok
@@ -568,10 +568,13 @@ def zigzag(
 
         initial_move_from_high = (initial_high - current_low) / initial_high
         initial_move_from_low = (current_high - initial_low) / initial_low
-        if (
+        is_initial_high_move_significant = (
             initial_move_from_high >= thresholds[initial_high_pos]
-            and initial_move_from_low >= thresholds[initial_low_pos]
-        ):
+        )
+        is_initial_low_move_significant = (
+            initial_move_from_low >= thresholds[initial_low_pos]
+        )
+        if is_initial_high_move_significant and is_initial_low_move_significant:
             if initial_move_from_high > initial_move_from_low:
                 if is_reversal_confirmed(
                     initial_high_pos, initial_high_pos, TrendDirection.DOWN
@@ -587,17 +590,13 @@ def zigzag(
                     state = TrendDirection.UP
                     break
         else:
-            if initial_move_from_high >= thresholds[
-                initial_high_pos
-            ] and is_reversal_confirmed(
+            if is_initial_high_move_significant and is_reversal_confirmed(
                 initial_high_pos, initial_high_pos, TrendDirection.DOWN
             ):
                 add_pivot(initial_high_pos, initial_high, TrendDirection.UP)
                 state = TrendDirection.DOWN
                 break
-            elif initial_move_from_low >= thresholds[
-                initial_low_pos
-            ] and is_reversal_confirmed(
+            elif is_initial_low_move_significant and is_reversal_confirmed(
                 initial_low_pos, initial_low_pos, TrendDirection.UP
             ):
                 add_pivot(initial_low_pos, initial_low, TrendDirection.DOWN)