]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
feat(qav3): add tunable to enable HPO search space reduction
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 21 Oct 2025 19:12:26 +0000 (21:12 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 21 Oct 2025 19:12:26 +0000 (21:12 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
README.md
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py
quickadapter/user_data/strategies/Utils.py

index 3bc7314b06f681523d768976db4074fca06e954f..b91a0e14c81d6e9fcfd6d237e3e3e7500251c417 100644 (file)
--- a/README.md
+++ b/README.md
@@ -35,56 +35,57 @@ docker compose up -d --build
 
 ### Configuration tunables
 
-| Path | Default | Type / Range | Description |
-|------|---------|-------------|-------------|
-| _Protections_ |  |  |  |
-| estimated_trade_duration_candles | 48 | int >= 1 | Heuristic for StoplossGuard tuning. |
-| _Exit pricing_ |  |  |  |
-| exit_pricing.trade_price_target | `moving_average` | enum {`moving_average`,`interpolation`,`weighted_interpolation`} | Trade NATR computation method. |
-| exit_pricing.thresholds_calibration.decline_quantile | 0.90 | float (0,1) | PNL decline quantile threshold. |
-| _Reversal confirmation_ |  |  |  |
-| reversal_confirmation.lookback_period | 0 | int >= 0 | Prior confirming candles; 0 = none. |
-| reversal_confirmation.decay_ratio | 0.5 | float (0,1] | Geometric per-step relaxation factor. |
-| _Regressor model_ |  |  |  |
-| freqai.regressor | `xgboost` | enum {`xgboost`,`lightgbm`} | Machine learning regressor algorithm. |
-| _Extrema smoothing_ |  |  |  |
-| freqai.extrema_smoothing | `gaussian` | enum {`gaussian`,`kaiser`,`triang`,`smm`,`sma`} | Extrema smoothing kernel (smm=simple moving median, sma=simple moving average). |
-| freqai.extrema_smoothing_window | 5 | int >= 1 | Window size for extrema smoothing. |
-| freqai.extrema_smoothing_beta | 8.0 | float > 0 | Kaiser kernel shape parameter. |
-| _Feature parameters_ |  |  |  |
-| freqai.feature_parameters.label_period_candles | 24 | int >= 1 | Zigzag NATR horizon. |
-| freqai.feature_parameters.label_natr_ratio | 9.0 | float > 0 | Zigzag NATR ratio. |
-| freqai.feature_parameters.min_label_natr_ratio | 9.0 | float > 0 | Minimum NATR ratio bound used by label HPO. |
-| freqai.feature_parameters.max_label_natr_ratio | 12.0 | float > 0 | Maximum NATR ratio bound used by label HPO. |
-| freqai.feature_parameters.label_frequency_candles | 12 | int >= 2 | Reversals labeling frequency. |
-| freqai.feature_parameters.label_metric | `euclidean` | string (supported: `euclidean`,`minkowski`,`cityblock`,`chebyshev`,`mahalanobis`,`seuclidean`,`jensenshannon`,`sqeuclidean`,...) | Metric used in distance calculations to ideal point. |
-| freqai.feature_parameters.label_weights | [0.5,0.5] | list[float] | Per-objective weights used in distance calculations to ideal point. |
-| freqai.feature_parameters.label_p_order | `None` | float | p-order used by Minkowski / power-mean calculations (optional). |
-| freqai.feature_parameters.label_medoid_metric | `euclidean` | string | Metric used with `medoid`. |
-| freqai.feature_parameters.label_kmeans_metric | `euclidean` | string | Metric used for k-means clustering. |
-| freqai.feature_parameters.label_kmeans_selection | `min` | enum {`min`,`medoid`} | Strategy to select trial in the best kmeans cluster. |
-| freqai.feature_parameters.label_kmedoids_metric | `euclidean` | string | Metric used for k-medoids clustering. |
-| freqai.feature_parameters.label_kmedoids_selection | `min` | enum {`min`,`medoid`} | Strategy to select trial in the best k-medoids cluster. |
-| freqai.feature_parameters.label_knn_metric | `minkowski` | string | Distance metric for KNN. |
-| freqai.feature_parameters.label_knn_p_order | `None` | float | p-order for KNN Minkowski metric distance. (optional) |
-| freqai.feature_parameters.label_knn_n_neighbors | 5 | int >= 1 | Number of neighbors for KNN. |
-| _Prediction thresholds_ |  |  |  |
-| freqai.prediction_thresholds_smoothing | `mean` | enum {`mean`,`isodata`,`li`,`minimum`,`otsu`,`triangle`,`yen`,`soft_extremum`} | Thresholding method for prediction thresholds smoothing. |
-| freqai.prediction_thresholds_alpha | 12.0 | float > 0 | Alpha for `soft_extremum`. |
-| freqai.outlier_threshold | 0.999 | float (0,1) | Quantile threshold for predictions outlier filtering. |
-| _Optuna / HPO_ |  |  |  |
-| freqai.optuna_hyperopt.enabled | true | bool | Enables HPO. |
-| freqai.optuna_hyperopt.n_jobs | CPU threads / 4 | int >= 1 | Parallel HPO workers. |
-| freqai.optuna_hyperopt.storage | `file` | enum {`file`,`sqlite`} | HPO storage backend. |
-| freqai.optuna_hyperopt.continuous | false | bool | Continuous HPO. |
-| freqai.optuna_hyperopt.warm_start | false | bool | Warm start HPO with previous best value(s). |
-| freqai.optuna_hyperopt.n_startup_trials | 15 | int >= 0 | HPO startup trials. |
-| freqai.optuna_hyperopt.n_trials | 50 | int >= 1 | Maximum HPO trials. |
-| freqai.optuna_hyperopt.timeout | 7200 | int >= 0 | HPO wall-clock timeout in seconds. |
-| freqai.optuna_hyperopt.label_candles_step | 1 | int >= 1 | Step for Zigzag NATR horizon search space. |
-| freqai.optuna_hyperopt.train_candles_step | 10 | int >= 1 | Step for training sets size search space. |
-| freqai.optuna_hyperopt.expansion_ratio | 0.4 | float [0,1] | HPO search space expansion ratio. |
-| freqai.optuna_hyperopt.seed | 1 | int >= 0 | HPO RNG seed. |
+| Path | Default          | Type / Range | Description                                                                     |
+|------|------------------|-------------|---------------------------------------------------------------------------------|
+| _Protections_ |                  |  |                                                                                 |
+| estimated_trade_duration_candles | 48               | int >= 1 | Heuristic for StoplossGuard tuning.                                             |
+| _Exit pricing_ |                  |  |                                                                                 |
+| exit_pricing.trade_price_target | `moving_average` | enum {`moving_average`,`interpolation`,`weighted_interpolation`} | Trade NATR computation method.                                                  |
+| exit_pricing.thresholds_calibration.decline_quantile | 0.90             | float (0,1) | PNL decline quantile threshold.                                                 |
+| _Reversal confirmation_ |                  |  |                                                                                 |
+| reversal_confirmation.lookback_period | 0                | int >= 0 | Prior confirming candles; 0 = none.                                             |
+| reversal_confirmation.decay_ratio | 0.5              | float (0,1] | Geometric per-step relaxation factor.                                           |
+| _Regressor model_ |                  |  |                                                                                 |
+| freqai.regressor | `xgboost`        | enum {`xgboost`,`lightgbm`} | Machine learning regressor algorithm.                                           |
+| _Extrema smoothing_ |                  |  |                                                                                 |
+| freqai.extrema_smoothing | `gaussian`       | enum {`gaussian`,`kaiser`,`triang`,`smm`,`sma`} | Extrema smoothing kernel (smm=simple moving median, sma=simple moving average). |
+| freqai.extrema_smoothing_window | 5                | int >= 1 | Window size for extrema smoothing.                                              |
+| freqai.extrema_smoothing_beta | 8.0              | float > 0 | Kaiser kernel shape parameter.                                                  |
+| _Feature parameters_ |                  |  |                                                                                 |
+| freqai.feature_parameters.label_period_candles | 24               | int >= 1 | Zigzag NATR horizon.                                                            |
+| freqai.feature_parameters.label_natr_ratio | 9.0              | float > 0 | Zigzag NATR ratio.                                                              |
+| freqai.feature_parameters.min_label_natr_ratio | 9.0              | float > 0 | Minimum NATR ratio bound used by label HPO.                                     |
+| freqai.feature_parameters.max_label_natr_ratio | 12.0             | float > 0 | Maximum NATR ratio bound used by label HPO.                                     |
+| freqai.feature_parameters.label_frequency_candles | 12               | int >= 2 | Reversals labeling frequency.                                                   |
+| freqai.feature_parameters.label_metric | `euclidean`      | string (supported: `euclidean`,`minkowski`,`cityblock`,`chebyshev`,`mahalanobis`,`seuclidean`,`jensenshannon`,`sqeuclidean`,...) | Metric used in distance calculations to ideal point.                            |
+| freqai.feature_parameters.label_weights | [0.5,0.5]        | list[float] | Per-objective weights used in distance calculations to ideal point.             |
+| freqai.feature_parameters.label_p_order | `None`           | float | p-order used by Minkowski / power-mean calculations (optional).                 |
+| freqai.feature_parameters.label_medoid_metric | `euclidean`      | string | Metric used with `medoid`.                                                      |
+| freqai.feature_parameters.label_kmeans_metric | `euclidean`      | string | Metric used for k-means clustering.                                             |
+| freqai.feature_parameters.label_kmeans_selection | `min`            | enum {`min`,`medoid`} | Strategy to select trial in the best kmeans cluster.                            |
+| freqai.feature_parameters.label_kmedoids_metric | `euclidean`      | string | Metric used for k-medoids clustering.                                           |
+| freqai.feature_parameters.label_kmedoids_selection | `min`            | enum {`min`,`medoid`} | Strategy to select trial in the best k-medoids cluster.                         |
+| freqai.feature_parameters.label_knn_metric | `minkowski`      | string | Distance metric for KNN.                                                        |
+| freqai.feature_parameters.label_knn_p_order | `None`           | float | p-order for KNN Minkowski metric distance. (optional)                           |
+| freqai.feature_parameters.label_knn_n_neighbors | 5                | int >= 1 | Number of neighbors for KNN.                                                    |
+| _Prediction thresholds_ |                  |  |                                                                                 |
+| freqai.prediction_thresholds_smoothing | `mean`           | enum {`mean`,`isodata`,`li`,`minimum`,`otsu`,`triangle`,`yen`,`soft_extremum`} | Thresholding method for prediction thresholds smoothing.                        |
+| freqai.prediction_thresholds_alpha | 12.0             | float > 0 | Alpha for `soft_extremum`.                                                      |
+| freqai.outlier_threshold | 0.999            | float (0,1) | Quantile threshold for predictions outlier filtering.                           |
+| _Optuna / HPO_ |                  |  |                                                                                 |
+| freqai.optuna_hyperopt.enabled | true             | bool | Enables HPO.                                                                    |
+| freqai.optuna_hyperopt.n_jobs | CPU threads / 4  | int >= 1 | Parallel HPO workers.                                                           |
+| freqai.optuna_hyperopt.storage | `file`           | enum {`file`,`sqlite`} | HPO storage backend.                                                            |
+| freqai.optuna_hyperopt.continuous | false            | bool | Continuous HPO.                                                                 |
+| freqai.optuna_hyperopt.warm_start | false            | bool | Warm start HPO with previous best value(s).                                     |
+| freqai.optuna_hyperopt.n_startup_trials | 15               | int >= 0 | HPO startup trials.                                                             |
+| freqai.optuna_hyperopt.n_trials | 50               | int >= 1 | Maximum HPO trials.                                                             |
+| freqai.optuna_hyperopt.timeout | 7200             | int >= 0 | HPO wall-clock timeout in seconds.                                              |
+| freqai.optuna_hyperopt.label_candles_step | 1                | int >= 1 | Step for Zigzag NATR horizon search space.                                      |
+| 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.seed | 1                | int >= 0 | HPO RNG seed.                                                                   |
 
 ## ReforceXY
 
@@ -153,4 +154,3 @@ docker compose down
 ## Note
 
 > Do not expect any support of any kind on the Internet. Nevertheless, PRs implementing documentation, bug fixes, cleanups or sensible features will be discussed and might get merged.
-
index c90635513109489635a9f576bba96ab9ac0cdef1..cd33696ce0559e95026901168a6d16029dfc3852 100644 (file)
@@ -81,6 +81,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
             "timeout": 7200,
             "label_candles_step": 1,
             "train_candles_step": 10,
+            "space_reduction": False,
             "expansion_ratio": 0.4,
             "seed": 1,
         }
@@ -317,6 +318,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
                     test_weights,
                     self.get_optuna_params(dk.pair, "hp"),
                     model_training_parameters,
+                    self._optuna_config.get("space_reduction"),
                     self._optuna_config.get("expansion_ratio"),
                 ),
                 direction=optuna.study.StudyDirection.MINIMIZE,
@@ -1735,10 +1737,15 @@ def hp_objective(
     test_weights: NDArray[np.floating],
     model_training_best_parameters: dict[str, Any],
     model_training_parameters: dict[str, Any],
+    space_reduction: bool,
     expansion_ratio: float,
 ) -> float:
     study_model_parameters = get_optuna_study_model_parameters(
-        trial, regressor, model_training_best_parameters, expansion_ratio
+        trial,
+        regressor,
+        model_training_best_parameters,
+        space_reduction,
+        expansion_ratio,
     )
     model_training_parameters = {**model_training_parameters, **study_model_parameters}
 
index 74dc2e99170c279302ad9bbc2d970d607b3e6d58..c40118be495d1a08eac32cdfb85f371acf7b427e 100644 (file)
@@ -827,6 +827,7 @@ def get_optuna_study_model_parameters(
     trial: optuna.trial.Trial,
     regressor: str,
     model_training_best_parameters: dict[str, Any],
+    space_reduction: bool,
     expansion_ratio: float,
 ) -> dict[str, Any]:
     if regressor not in regressors:
@@ -864,7 +865,7 @@ def get_optuna_study_model_parameters(
     }
 
     ranges = copy.deepcopy(default_ranges)
-    if model_training_best_parameters:
+    if space_reduction and model_training_best_parameters:
         for param, (default_min, default_max) in default_ranges.items():
             center_value = model_training_best_parameters.get(param)