]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
fix(qav3): recalibrate pivot optimization to avoid failed study
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 22 May 2025 19:13:53 +0000 (21:13 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 22 May 2025 19:13:53 +0000 (21:13 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
ReforceXY/user_data/freqaimodels/ReforceXY.py
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py
quickadapter/user_data/strategies/QuickAdapterV3.py
quickadapter/user_data/strategies/Utils.py

index c9ff9c4f9228fc04694200489835ce528e24822f..ebc3b9dc15a1f6f3b451b64a1076e26c01b6efb9 100644 (file)
@@ -20,7 +20,7 @@ from optuna.exceptions import ExperimentalWarning
 from optuna.pruners import HyperbandPruner
 from optuna.samplers import TPESampler
 from optuna.study import Study, StudyDirection
-from optuna.storages import JournalStorage, BaseStorage
+from optuna.storages import BaseStorage, JournalStorage, RDBStorage
 from optuna.storages.journal import JournalFileBackend
 from pandas import DataFrame, concat, merge
 from sb3_contrib.common.maskable.callbacks import MaskableEvalCallback
@@ -494,7 +494,9 @@ class ReforceXY(BaseReinforcementLearningModel):
         storage_filename = f"optuna-{pair.split('/')[0]}" if pair else "optuna"
         storage_backend = self.rl_config_optuna.get("storage", "sqlite")
         if storage_backend == "sqlite":
-            storage = f"sqlite:///{storage_dir}/{storage_filename}.sqlite"
+            storage = RDBStorage(
+                url=f"sqlite:///{storage_dir}/{storage_filename}.sqlite"
+            )
         elif storage_backend == "file":
             storage = JournalStorage(
                 JournalFileBackend(f"{storage_dir}/{storage_filename}.log")
index 3a775f1a144a9215377220b9b0592a655b17827a..0ead289a0dba4b56e976c170b5fd8086d8e3dbb3 100644 (file)
@@ -45,7 +45,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
     https://github.com/sponsors/robcaulk
     """
 
-    version = "3.7.54"
+    version = "3.7.55"
 
     @cached_property
     def _optuna_config(self) -> dict:
@@ -535,7 +535,13 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
         storage_filename = f"optuna-{pair.split('/')[0]}"
         storage_backend = self._optuna_config.get("storage")
         if storage_backend == "sqlite":
-            storage = f"sqlite:///{storage_dir}/{storage_filename}.sqlite"
+            storage = optuna.storages.RDBStorage(
+                url=f"sqlite:///{storage_dir}/{storage_filename}.sqlite",
+                heartbeat_interval=60,
+                failed_trial_callback=optuna.storages.RetryFailedTrialCallback(
+                    max_retry=3
+                ),
+            )
         elif storage_backend == "file":
             storage = optuna.storages.JournalStorage(
                 optuna.storages.journal.JournalFileBackend(
@@ -929,21 +935,22 @@ def zigzag(
         min_depth: int = 6,
         max_depth: int = 36,
     ) -> int:
-        if len(pivots_indices) < 2:
+        if not pivots_indices:
             return min_depth
+        depth_factor = calculate_depth_factor(pos)
+        if len(pivots_indices) < 2:
+            return np.clip(int(min_depth * depth_factor), min_depth, max_depth)
 
         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)
 
-        depth_factor = calculate_depth_factor(pos)
-
         return np.clip(int(average_period * depth_factor), min_depth, max_depth)
 
     def calculate_min_slope_strength(
         pos: int,
-        min_strength: float = 1.025,
-        max_strength: float = 1.525,
+        min_strength: float = 1.0 + np.finfo(float).eps,
+        max_strength: float = 1.5 + np.finfo(float).eps,
     ) -> float:
         start = max(0, pos - natr_period)
         end = min(pos + 1, n)
index dacf292f8d998d20d84480b2875001e3e65327ca..74cfa2725a8379c370f10e008a83ecb94c1835bf 100644 (file)
@@ -60,7 +60,7 @@ class QuickAdapterV3(IStrategy):
     INTERFACE_VERSION = 3
 
     def version(self) -> str:
-        return "3.3.54"
+        return "3.3.55"
 
     timeframe = "5m"
 
index 7f8a5963b9e262fcd0bd19b37c12bd1a09eeab81..142c1d754f3eb923e78bc6b5685ec70419d0740b 100644 (file)
@@ -418,21 +418,22 @@ def zigzag(
         min_depth: int = 6,
         max_depth: int = 36,
     ) -> int:
-        if len(pivots_indices) < 2:
+        if not pivots_indices:
             return min_depth
+        depth_factor = calculate_depth_factor(pos)
+        if len(pivots_indices) < 2:
+            return np.clip(int(min_depth * depth_factor), min_depth, max_depth)
 
         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)
 
-        depth_factor = calculate_depth_factor(pos)
-
         return np.clip(int(average_period * depth_factor), min_depth, max_depth)
 
     def calculate_min_slope_strength(
         pos: int,
-        min_strength: float = 1.025,
-        max_strength: float = 1.525,
+        min_strength: float = 1.0 + np.finfo(float).eps,
+        max_strength: float = 1.5 + np.finfo(float).eps,
     ) -> float:
         start = max(0, pos - natr_period)
         end = min(pos + 1, n)