]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
refactor(qav3): align pivot confirmation checks behavior
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 23 May 2025 12:02:37 +0000 (14:02 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 23 May 2025 12:02:37 +0000 (14:02 +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 eba8d66b8c13639d083ee331b2e56e6ca4c99b1b..fdb42b242ab5a3a72a0751c4188f50a77b3d0940 100644 (file)
@@ -45,7 +45,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
     https://github.com/sponsors/robcaulk
     """
 
-    version = "3.7.57"
+    version = "3.7.58"
 
     @cached_property
     def _optuna_config(self) -> dict:
@@ -934,9 +934,7 @@ def zigzag(
     ) -> int:
         quantile = volatility_quantile(pos)
         if np.isnan(quantile):
-            return np.clip(
-                round(np.median([min_window, max_window]), min_window, max_window)
-            ).astype(int)
+            return int(round(np.median([min_window, max_window])))
 
         return np.clip(
             round(max_window - (max_window - min_window) * quantile),
@@ -944,38 +942,19 @@ def zigzag(
             max_window,
         ).astype(int)
 
-    def calculate_depth_factor(
-        pos: int,
-        min_factor: float = 0.5,
-        max_factor: float = 1.5,
-    ) -> float:
-        quantile = volatility_quantile(pos)
-        if np.isnan(quantile):
-            return np.median([min_factor, max_factor])
-
-        return max_factor - (max_factor - min_factor) * quantile
-
     def calculate_depth(
         pos: int,
         min_depth: int = 6,
-        max_depth: int = 36,
+        max_depth: int = 24,
     ) -> int:
-        if not pivots_indices:
-            return min_depth
-        depth_factor = calculate_depth_factor(pos)
-        if len(pivots_indices) < 2:
-            return np.clip(
-                round(np.median([min_depth, max_depth]) * depth_factor),
-                min_depth,
-                max_depth,
-            ).astype(int)
-
-        previous_periods = np.diff(pivots_indices[-3:])
-        weights = np.linspace(0.5, 1.5, len(previous_periods))
-        average_period = np.average(previous_periods, weights=weights)
+        quantile = volatility_quantile(pos)
+        if np.isnan(quantile):
+            return int(round(np.median([min_depth, max_depth])))
 
         return np.clip(
-            round(average_period * depth_factor), min_depth, max_depth
+            round(max_depth - (max_depth - min_depth) * quantile),
+            min_depth,
+            max_depth,
         ).astype(int)
 
     def calculate_min_slope_strength(
index 14b9a1179aa6844e63d464cc89b89f2a2462bfad..ff28dea3495e3dfe608202e290b897b95cba760d 100644 (file)
@@ -60,7 +60,7 @@ class QuickAdapterV3(IStrategy):
     INTERFACE_VERSION = 3
 
     def version(self) -> str:
-        return "3.3.57"
+        return "3.3.58"
 
     timeframe = "5m"
 
index 6b0e839a2ca95a33733c37d1433e5fd1b1dc8984..0d7809c3a02b282cd27153c70fe3716244eb9ed6 100644 (file)
@@ -418,9 +418,7 @@ def zigzag(
     ) -> int:
         quantile = volatility_quantile(pos)
         if np.isnan(quantile):
-            return np.clip(
-                round(np.median([min_window, max_window])), min_window, max_window
-            ).astype(int)
+            return int(round(np.median([min_window, max_window])))
 
         return np.clip(
             round(max_window - (max_window - min_window) * quantile),
@@ -428,38 +426,19 @@ def zigzag(
             max_window,
         ).astype(int)
 
-    def calculate_depth_factor(
-        pos: int,
-        min_factor: float = 0.5,
-        max_factor: float = 1.5,
-    ) -> float:
-        quantile = volatility_quantile(pos)
-        if np.isnan(quantile):
-            return np.median([min_factor, max_factor])
-
-        return max_factor - (max_factor - min_factor) * quantile
-
     def calculate_depth(
         pos: int,
         min_depth: int = 6,
-        max_depth: int = 36,
+        max_depth: int = 24,
     ) -> int:
-        if not pivots_indices:
-            return min_depth
-        depth_factor = calculate_depth_factor(pos)
-        if len(pivots_indices) < 2:
-            return np.clip(
-                round(np.median([min_depth, max_depth]) * depth_factor),
-                min_depth,
-                max_depth,
-            ).astype(int)
-
-        previous_periods = np.diff(pivots_indices[-3:])
-        weights = np.linspace(0.5, 1.5, len(previous_periods))
-        average_period = np.average(previous_periods, weights=weights)
+        quantile = volatility_quantile(pos)
+        if np.isnan(quantile):
+            return int(round(np.median([min_depth, max_depth])))
 
         return np.clip(
-            round(average_period * depth_factor), min_depth, max_depth
+            round(max_depth - (max_depth - min_depth) * quantile),
+            min_depth,
+            max_depth,
         ).astype(int)
 
     def calculate_min_slope_strength(