]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
refactor(qav3): cleanup optuna code
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 8 Nov 2025 21:21:55 +0000 (22:21 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 8 Nov 2025 21:21:55 +0000 (22:21 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
README.md
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py

index 04ee891507680164e37c7b906bfe1426b3124ba4..7a21bbad8b03f3829bb1523bfd48d8184a57a8be 100644 (file)
--- a/README.md
+++ b/README.md
@@ -91,6 +91,7 @@ docker compose up -d --build
 | freqai.optuna_hyperopt.train_candles_step | 10               | int >= 1 | Step for training sets size search space.                                       |
 | freqai.optuna_hyperopt.space_reduction | false            | bool | Enable/disable HPO search space reduction based on previous best parameters.    |
 | freqai.optuna_hyperopt.expansion_ratio | 0.4              | float [0,1] | HPO search space expansion ratio.                                               |
+| freqai.optuna_hyperopt.min_resource | 3                | int >= 1 | Minimum resource per Hyperband pruner rung.           |
 | freqai.optuna_hyperopt.seed | 1                | int >= 0 | HPO RNG seed.                                                                   |
 
 ## ReforceXY
index 7378613086d3d8b0293cd63c9c32f9aa52bdb833..bec54c541d9cf5f4bb75663fcc02d07b1020aa93 100644 (file)
@@ -84,6 +84,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
             "train_candles_step": 10,
             "space_reduction": False,
             "expansion_ratio": 0.4,
+            "min_resource": 3,
             "seed": 1,
         }
         return {
@@ -1533,8 +1534,17 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
             raise ValueError(
                 "Cannot specify both 'direction' and 'directions'. Use one or the other"
             )
+
+        is_study_single_objective = direction is not None and directions is None
+        if not is_study_single_objective:
+            if directions is None or len(directions) < 2:
+                raise ValueError(
+                    "Multi-objective study must have at least 2 directions specified"
+                )
+
         identifier = self.freqai_info.get("identifier")
         study_name = f"{identifier}-{pair}-{namespace}"
+
         try:
             storage = self.optuna_storage(pair)
         except Exception as e:
@@ -1548,19 +1558,13 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
         if continuous:
             QuickAdapterRegressorV3.optuna_study_delete(study_name, storage)
 
-        is_study_single_objective = direction is not None and directions is None
-        if (
-            not is_study_single_objective
-            and isinstance(directions, list)
-            and len(directions) < 2
-        ):
-            raise ValueError(
-                "Multi-objective study must have at least 2 directions specified"
-            )
         if is_study_single_objective:
-            pruner = optuna.pruners.HyperbandPruner(min_resource=3)
+            pruner = optuna.pruners.HyperbandPruner(
+                min_resource=self._optuna_config.get("min_resource")
+            )
         else:
             pruner = optuna.pruners.NopPruner()
+
         try:
             return optuna.create_study(
                 study_name=study_name,
@@ -1861,7 +1865,7 @@ def label_objective(
     df = df.iloc[-(max(2, int(label_period_cycles)) * label_period_candles) :]
 
     if df.empty:
-        return -np.inf, -np.inf
+        return -np.inf, 0
 
     _, pivots_values, _, pivots_thresholds = zigzag(
         df,