]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
fix(qav3): ensure trade exit condition handle prediction outliers
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 5 Mar 2025 17:32:01 +0000 (18:32 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Wed, 5 Mar 2025 17:32:01 +0000 (18:32 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/LightGBMRegressorQuickAdapterV35.py
quickadapter/user_data/freqaimodels/XGBoostRegressorQuickAdapterV35.py
quickadapter/user_data/strategies/QuickAdapterV3.py

index c2727f74d04302198987481424560437583ee30e..3a818519aa5b4af4ae00175a0afc23639b6ebae2 100644 (file)
@@ -410,7 +410,7 @@ class LightGBMRegressorQuickAdapterV35(BaseRegressionModel):
                     test_weights,
                     self.data_split_parameters.get("test_size", TEST_SIZE),
                     self.freqai_info.get("fit_live_predictions_candles", 100),
-                    self.__optuna_config.get("candles_step", 100),
+                    self.__optuna_config.get("candles_step", 10),
                     model_training_parameters,
                 ),
                 n_trials=self.__optuna_config.get("n_trials", N_TRIALS),
@@ -585,7 +585,7 @@ def period_objective(
     )
     y_pred = model.predict(X_test)
 
-    min_label_period_candles: int = max(fit_live_predictions_candles // 200, 10)
+    min_label_period_candles: int = 10
     max_label_period_candles: int = max(
         fit_live_predictions_candles // 6, min_label_period_candles
     )
index e70f0caea7c8d25fbcf3ab0638f73816b3b3f245..9957a2ca48090a6cb2fab03255d007ecf3a3bae2 100644 (file)
@@ -411,7 +411,7 @@ class XGBoostRegressorQuickAdapterV35(BaseRegressionModel):
                     test_weights,
                     self.data_split_parameters.get("test_size", TEST_SIZE),
                     self.freqai_info.get("fit_live_predictions_candles", 100),
-                    self.__optuna_config.get("candles_step", 100),
+                    self.__optuna_config.get("candles_step", 10),
                     model_training_parameters,
                 ),
                 n_trials=self.__optuna_config.get("n_trials", N_TRIALS),
@@ -589,7 +589,7 @@ def period_objective(
     )
     y_pred = model.predict(X_test)
 
-    min_label_period_candles: int = max(fit_live_predictions_candles // 200, 10)
+    min_label_period_candles: int = 10
     max_label_period_candles: int = max(
         fit_live_predictions_candles // 6, min_label_period_candles
     )
index 17b03280a7023b1d66756ce4c72072f4bb27c366..fcde1d018bfd0f5937838d76bb950299f8832a78 100644 (file)
@@ -1,14 +1,12 @@
 import logging
 from functools import reduce
 import datetime
-from datetime import timedelta
 import talib.abstract as ta
 from pandas import DataFrame, Series
 from technical import qtpylib
 from typing import Optional
 from freqtrade.strategy.interface import IStrategy
 from technical.pivots_points import pivots_points
-from freqtrade.exchange import timeframe_to_prev_date
 from freqtrade.persistence import Trade
 from scipy.signal import argrelmin, argrelmax
 import numpy as np
@@ -322,29 +320,21 @@ class QuickAdapterV3(IStrategy):
         )
 
         last_candle = dataframe.iloc[-1].squeeze()
-        trade_date = timeframe_to_prev_date(
-            self.timeframe,
-            (trade.open_date_utc - timedelta(minutes=int(self.timeframe[:-1]))),
-        )
-        trade_candle = dataframe.loc[(dataframe["date"] == trade_date)]
-        if trade_candle.empty:
-            return None
-        trade_candle = trade_candle.squeeze()
-
-        entry_tag = trade.enter_tag
-
         if last_candle["DI_catch"] == 0:
             return "outlier_detected"
 
+        enter_tag = trade.enter_tag
         if (
-            last_candle[EXTREMA_COLUMN] < last_candle["minima_threshold"]
-            and entry_tag == "short"
+            enter_tag == "short"
+            and last_candle["do_predict"] == 1
+            and last_candle[EXTREMA_COLUMN] < last_candle["minima_threshold"]
         ):
             return "minima_detected_short"
 
         if (
-            last_candle[EXTREMA_COLUMN] > last_candle["maxima_threshold"]
-            and entry_tag == "long"
+            enter_tag == "long"
+            and last_candle["do_predict"] == 1
+            and last_candle[EXTREMA_COLUMN] > last_candle["maxima_threshold"]
         ):
             return "maxima_detected_long"