]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
perf(qav3): tune pivot labeling optimization
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 10 May 2025 13:08:37 +0000 (15:08 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 10 May 2025 13:08:37 +0000 (15:08 +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 65b68457f9ee6143ca5346d4dc0d0cd8365b0a11..3bf4961de879f4b93ec6b4f688762d249e142662 100644 (file)
@@ -45,7 +45,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
     https://github.com/sponsors/robcaulk
     """
 
-    version = "3.7.31"
+    version = "3.7.32"
 
     @cached_property
     def _optuna_config(self) -> dict:
@@ -914,8 +914,24 @@ def zigzag(
         previous_closes = closes[previous_slice]
         previous_highs = highs[previous_slice]
         previous_lows = lows[previous_slice]
-        if len(next_closes) == 0 or len(previous_closes) == 0:
-            return False
+
+        local_extrema_ok = False
+        if direction == TrendDirection.DOWN:
+            if (
+                np.all(next_closes < highs[candidate_pivot_pos])
+                and np.all(previous_closes < highs[candidate_pivot_pos])
+                and np.max(next_highs) <= highs[candidate_pivot_pos]
+                and np.max(previous_highs) <= highs[candidate_pivot_pos]
+            ):
+                local_extrema_ok = True
+        elif direction == TrendDirection.UP:
+            if (
+                np.all(next_closes > lows[candidate_pivot_pos])
+                and np.all(previous_closes > lows[candidate_pivot_pos])
+                and np.min(next_lows) >= lows[candidate_pivot_pos]
+                and np.min(previous_lows) >= lows[candidate_pivot_pos]
+            ):
+                local_extrema_ok = True
 
         slope_ok = True
         if len(next_closes) >= 2:
@@ -925,7 +941,7 @@ def zigzag(
             elif direction == TrendDirection.UP:
                 slope_ok = next_slope > 0
 
-        thresholds_ratio = 0.175
+        thresholds_ratio = 0.25
         significant_move_away_ok = False
         if direction == TrendDirection.DOWN:
             if np.any(
@@ -942,25 +958,7 @@ def zigzag(
             ):
                 significant_move_away_ok = True
 
-        if direction == TrendDirection.DOWN:
-            return (
-                np.all(next_closes < highs[candidate_pivot_pos])
-                and np.all(previous_closes < highs[candidate_pivot_pos])
-                and np.max(next_highs) <= highs[candidate_pivot_pos]
-                and np.max(previous_highs) <= highs[candidate_pivot_pos]
-                and slope_ok
-                and significant_move_away_ok
-            )
-        elif direction == TrendDirection.UP:
-            return (
-                np.all(next_closes > lows[candidate_pivot_pos])
-                and np.all(previous_closes > lows[candidate_pivot_pos])
-                and np.min(next_lows) >= lows[candidate_pivot_pos]
-                and np.min(previous_lows) >= lows[candidate_pivot_pos]
-                and slope_ok
-                and significant_move_away_ok
-            )
-        return False
+        return local_extrema_ok and slope_ok and significant_move_away_ok
 
     start_pos = 0
     initial_high_pos = start_pos
@@ -1052,7 +1050,7 @@ def label_objective(
         max_label_period_candles,
         step=candles_step,
     )
-    label_natr_ratio = trial.suggest_float("label_natr_ratio", 0.07, 0.2)
+    label_natr_ratio = trial.suggest_float("label_natr_ratio", 0.08, 0.25)
 
     df = df.iloc[
         -(
index c0723bb7778e1e21dc9df1446235bcf272777087..aa8df4ef242a216df37843944b1e6d58c961177f 100644 (file)
@@ -58,7 +58,7 @@ class QuickAdapterV3(IStrategy):
     INTERFACE_VERSION = 3
 
     def version(self) -> str:
-        return "3.3.27"
+        return "3.3.28"
 
     timeframe = "5m"
 
index cda7e981dcb3a49b63ab7a7eb6448bfc2de12c17..daf7d7e02803a1c71edb2fec72b244c9d589e518 100644 (file)
@@ -408,8 +408,24 @@ def zigzag(
         previous_closes = closes[previous_slice]
         previous_highs = highs[previous_slice]
         previous_lows = lows[previous_slice]
-        if len(next_closes) == 0 or len(previous_closes) == 0:
-            return False
+
+        local_extrema_ok = False
+        if direction == TrendDirection.DOWN:
+            if (
+                np.all(next_closes < highs[candidate_pivot_pos])
+                and np.all(previous_closes < highs[candidate_pivot_pos])
+                and np.max(next_highs) <= highs[candidate_pivot_pos]
+                and np.max(previous_highs) <= highs[candidate_pivot_pos]
+            ):
+                local_extrema_ok = True
+        elif direction == TrendDirection.UP:
+            if (
+                np.all(next_closes > lows[candidate_pivot_pos])
+                and np.all(previous_closes > lows[candidate_pivot_pos])
+                and np.min(next_lows) >= lows[candidate_pivot_pos]
+                and np.min(previous_lows) >= lows[candidate_pivot_pos]
+            ):
+                local_extrema_ok = True
 
         slope_ok = True
         if len(next_closes) >= 2:
@@ -419,7 +435,7 @@ def zigzag(
             elif direction == TrendDirection.UP:
                 slope_ok = next_slope > 0
 
-        thresholds_ratio = 0.175
+        thresholds_ratio = 0.25
         significant_move_away_ok = False
         if direction == TrendDirection.DOWN:
             if np.any(
@@ -436,25 +452,7 @@ def zigzag(
             ):
                 significant_move_away_ok = True
 
-        if direction == TrendDirection.DOWN:
-            return (
-                np.all(next_closes < highs[candidate_pivot_pos])
-                and np.all(previous_closes < highs[candidate_pivot_pos])
-                and np.max(next_highs) <= highs[candidate_pivot_pos]
-                and np.max(previous_highs) <= highs[candidate_pivot_pos]
-                and slope_ok
-                and significant_move_away_ok
-            )
-        elif direction == TrendDirection.UP:
-            return (
-                np.all(next_closes > lows[candidate_pivot_pos])
-                and np.all(previous_closes > lows[candidate_pivot_pos])
-                and np.min(next_lows) >= lows[candidate_pivot_pos]
-                and np.min(previous_lows) >= lows[candidate_pivot_pos]
-                and slope_ok
-                and significant_move_away_ok
-            )
-        return False
+        return local_extrema_ok and slope_ok and significant_move_away_ok
 
     start_pos = 0
     initial_high_pos = start_pos