From: Jérôme Benoit Date: Sat, 8 Nov 2025 21:21:55 +0000 (+0100) Subject: refactor(qav3): cleanup optuna code X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=664423a63b128fe9520ac02bc32dff0eb605eed7;p=freqai-strategies.git refactor(qav3): cleanup optuna code Signed-off-by: Jérôme Benoit --- diff --git a/README.md b/README.md index 04ee891..7a21bba 100644 --- 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 diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index 7378613..bec54c5 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -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,