]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
feat(qav3): add optuna hyperopt tunables
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 9 Mar 2025 10:38:41 +0000 (11:38 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 9 Mar 2025 10:38:41 +0000 (11:38 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
ReforceXY/user_data/config-template.json
ReforceXY/user_data/freqaimodels/ReforceXY.py
ReforceXY/user_data/strategies/RLAgentStrategy.py
quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py
quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py

index 15237b020d21b0e7ba03dea479f3c8e657ea0630..35433b3044c9c303bcd81f7bd8aa25990db4c8e9 100644 (file)
@@ -16,7 +16,7 @@
   "minimal_roi": {
     "0": 0.03
   }, // Take_profit exit value used with force_actions
-  "stoploss": -0.03, // Stop_loss exit value used with force_actions
+  "stoploss": -0.02, // Stop_loss exit value used with force_actions
   "unfilledtimeout": {
     "entry": 10,
     "exit": 10,
index 5d04f27379241bc9e0adc8c9a2b414582a44d359..7fc04ec9f7a188b6b19f0a526081da7c9f3381bc 100644 (file)
@@ -65,7 +65,7 @@ class ReforceXY(BaseReinforcementLearningModel):
         "freqaimodel": "ReforceXY",
         "strategy": "RLAgentStrategy",
         "minimal_roi": {"0": 0.03},                 // Take_profit exit value used with force_actions
-        "stoploss": -0.03,                          // Stop_loss exit value used with force_actions
+        "stoploss": -0.02,                          // Stop_loss exit value used with force_actions
         ...
         "freqai": {
             ...
index 38053d72759ed4331cd9f1d86f32ff92ebbb6952..99a4b9c71757ee729ffeec0fedc0acbc82024c84 100644 (file)
@@ -20,10 +20,41 @@ class RLAgentStrategy(IStrategy):
     minimal_roi = {"0": 0.03}
 
     process_only_new_candles = True
-    stoploss = -0.03
+
+    stoploss = -0.02
+    # Trailing stop:
+    trailing_stop = True
+    trailing_stop_positive = 0.0099
+    trailing_stop_positive_offset = 0.01
+    trailing_only_offset_is_reached = True
+
     use_exit_signal = True
+
     startup_candle_count: int = 300
 
+    # @property
+    # def protections(self):
+    #     fit_live_predictions_candles = self.freqai_info.get(
+    #         "fit_live_predictions_candles", 100
+    #     )
+    #     return [
+    #         {"method": "CooldownPeriod", "stop_duration_candles": 4},
+    #         {
+    #             "method": "MaxDrawdown",
+    #             "lookback_period_candles": 48,
+    #             "trade_limit": 20,
+    #             "stop_duration_candles": 4,
+    #             "max_allowed_drawdown": 0.2,
+    #         },
+    #         {
+    #             "method": "StoplossGuard",
+    #             "lookback_period_candles": int(fit_live_predictions_candles / 2),
+    #             "trade_limit": 1,
+    #             "stop_duration_candles": int(fit_live_predictions_candles / 2),
+    #             "only_per_pair": True,
+    #         },
+    #     ]
+
     @property
     def can_short(self):
         return self.is_short_allowed()
index 5bb6ebc5ac7f2f9404f8dfb10471123cf18a5fe6..3107ae717eb8a1a6d97c56ef508a02df7063cafd 100644 (file)
@@ -308,7 +308,8 @@ class LightGBMRegressorQuickAdapterV35(BaseRegressionModel):
         study_name = f"{identifier}-{study_namespace}-{pair}"
         storage = self.optuna_storage(pair)
         pruner = optuna.pruners.HyperbandPruner()
-        self.optuna_study_delete(study_name, storage)
+        if self.__optuna_config.get("continuous", True):
+            self.optuna_study_delete(study_name, storage)
         study = optuna.create_study(
             study_name=study_name,
             sampler=optuna.samplers.TPESampler(
@@ -319,7 +320,8 @@ class LightGBMRegressorQuickAdapterV35(BaseRegressionModel):
             direction=optuna.study.StudyDirection.MINIMIZE,
             storage=storage,
         )
-        self.optuna_hp_enqueue_previous_best_trial(pair, study)
+        if self.__optuna_config.get("warm_start", True):
+            self.optuna_hp_enqueue_previous_best_trial(pair, study)
         logger.info(f"Optuna {study_namespace} hyperopt started")
         start = time.time()
         try:
@@ -384,7 +386,8 @@ class LightGBMRegressorQuickAdapterV35(BaseRegressionModel):
         study_name = f"{identifier}-{study_namespace}-{pair}"
         storage = self.optuna_storage(pair)
         pruner = optuna.pruners.HyperbandPruner()
-        self.optuna_study_delete(study_name, storage)
+        if self.__optuna_config.get("continuous", True):
+            self.optuna_study_delete(study_name, storage)
         study = optuna.create_study(
             study_name=study_name,
             sampler=optuna.samplers.TPESampler(
@@ -395,7 +398,8 @@ class LightGBMRegressorQuickAdapterV35(BaseRegressionModel):
             direction=optuna.study.StudyDirection.MINIMIZE,
             storage=storage,
         )
-        self.optuna_period_enqueue_previous_best_trial(pair, study)
+        if self.__optuna_config.get("warm_start", True):
+            self.optuna_period_enqueue_previous_best_trial(pair, study)
         logger.info(f"Optuna {study_namespace} hyperopt started")
         start = time.time()
         try:
index 010a3b921c7fd2d1da99bd1feb27c5b7370c4980..3b94dfaa4058d71e817f910395e3e83d21ba8857 100644 (file)
@@ -309,7 +309,8 @@ class XGBoostRegressorQuickAdapterV35(BaseRegressionModel):
         study_name = f"{identifier}-{study_namespace}-{pair}"
         storage = self.optuna_storage(pair)
         pruner = optuna.pruners.HyperbandPruner()
-        self.optuna_study_delete(study_name, storage)
+        if self.__optuna_config.get("continuous", True):
+            self.optuna_study_delete(study_name, storage)
         study = optuna.create_study(
             study_name=study_name,
             sampler=optuna.samplers.TPESampler(
@@ -320,7 +321,8 @@ class XGBoostRegressorQuickAdapterV35(BaseRegressionModel):
             direction=optuna.study.StudyDirection.MINIMIZE,
             storage=storage,
         )
-        self.optuna_hp_enqueue_previous_best_trial(pair, study)
+        if self.__optuna_config.get("warm_start", True):
+            self.optuna_hp_enqueue_previous_best_trial(pair, study)
         logger.info(f"Optuna {study_namespace} hyperopt started")
         start = time.time()
         try:
@@ -385,7 +387,8 @@ class XGBoostRegressorQuickAdapterV35(BaseRegressionModel):
         study_name = f"{identifier}-{study_namespace}-{pair}"
         storage = self.optuna_storage(pair)
         pruner = optuna.pruners.HyperbandPruner()
-        self.optuna_study_delete(study_name, storage)
+        if self.__optuna_config.get("continuous", True):
+            self.optuna_study_delete(study_name, storage)
         study = optuna.create_study(
             study_name=study_name,
             sampler=optuna.samplers.TPESampler(
@@ -396,7 +399,8 @@ class XGBoostRegressorQuickAdapterV35(BaseRegressionModel):
             direction=optuna.study.StudyDirection.MINIMIZE,
             storage=storage,
         )
-        self.optuna_period_enqueue_previous_best_trial(pair, study)
+        if self.__optuna_config.get("warm_start", True):
+            self.optuna_period_enqueue_previous_best_trial(pair, study)
         logger.info(f"Optuna {study_namespace} hyperopt started")
         start = time.time()
         try: