]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
refactor(qav3): TP code cleanups
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 3 May 2025 19:27:43 +0000 (21:27 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 3 May 2025 19:27:43 +0000 (21:27 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py
quickadapter/user_data/strategies/QuickAdapterV3.py

index 94c78b9c7f57ec77ad844268ec632ffc793af188..8254abdb1c35405ac15eb829093f462f90ca467c 100644 (file)
@@ -967,10 +967,10 @@ def label_objective(
     fit_live_predictions_candles: int,
     candles_step: int,
 ) -> tuple[float, int]:
-    min_label_period_candles: int = round_to_nearest(
+    min_label_period_candles: int = round_to_nearest_int(
         max(fit_live_predictions_candles // 16, 20), candles_step
     )
-    max_label_period_candles: int = round_to_nearest(
+    max_label_period_candles: int = round_to_nearest_int(
         max(fit_live_predictions_candles // 4, min_label_period_candles),
         candles_step,
     )
@@ -1046,7 +1046,7 @@ def boltzmann_operator(series: pd.Series, alpha: float) -> float:
     return numerator / denominator
 
 
-def round_to_nearest(value: float, step: int) -> int:
+def round_to_nearest_int(value: float, step: int) -> int:
     """
     Round a value to the nearest multiple of a given step.
     :param value: The value to round.
index a8a1e016a5eb6b5622f48a4c44409771ae044d92..c9bc56d126abd8776605e8494ba8bafefc6700c5 100644 (file)
@@ -509,7 +509,6 @@ class QuickAdapterV3(IStrategy):
         current_natr = df["natr_label_period_candles"].iloc[-1]
         if isna(current_natr):
             return None
-        take_profit_natr_ratio = self.get_take_profit_natr_ratio(trade.pair)
         natr_change_pct = abs(current_natr - entry_natr) / entry_natr
         if natr_change_pct > 0.2:
             if current_natr > entry_natr:
@@ -521,13 +520,15 @@ class QuickAdapterV3(IStrategy):
         else:
             entry_natr_weight = 0.5
             current_natr_weight = 0.5
-        blended_take_profit_natr = (
+        take_profit_natr = (
             entry_natr_weight * entry_natr + current_natr_weight * current_natr
         )
-        take_profit_distance = (
-            trade.open_rate * blended_take_profit_natr * take_profit_natr_ratio
+        return (
+            trade.open_rate
+            * take_profit_natr
+            * self.get_take_profit_natr_ratio(trade.pair)
+            * math.log10(9 + trade_duration_candles)
         )
-        return take_profit_distance * math.log10(9 + trade_duration_candles)
 
     def custom_stoploss(
         self,