]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
perf(qav3): compute the secure take profit price from the partial exit
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 20 Jul 2025 17:34:50 +0000 (19:34 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 20 Jul 2025 17:34:50 +0000 (19:34 +0200)
stages

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py
quickadapter/user_data/strategies/QuickAdapterV3.py
quickadapter/user_data/strategies/Utils.py

index f3ca6548e5bbea4df28d5e5cca9152f2893b37f6..dfe5a0785ddeafa7c7590af18b1a6f763c3e9d70 100644 (file)
@@ -280,7 +280,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
 
         model_training_parameters = self.model_training_parameters
 
-        start = time.time()
+        start_time = time.time()
         if self._optuna_hyperopt:
             self.optuna_optimize(
                 pair=dk.pair,
@@ -356,7 +356,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
             model_training_parameters=model_training_parameters,
             init_model=self.get_init_model(dk.pair),
         )
-        time_spent = time.time() - start
+        time_spent = time.time() - start_time
         self.dd.update_metric_tracker("fit_time", time_spent, dk.pair)
 
         return model
@@ -1437,13 +1437,13 @@ def zigzag(
 
     def calculate_volatility_quantile(pos: int) -> float:
         if pos not in volatility_quantile_cache:
-            start = max(0, pos + 1 - natr_period)
-            end = min(pos + 1, n)
-            if start >= end:
+            start_pos = max(0, pos + 1 - natr_period)
+            end_pos = min(pos + 1, n)
+            if start_pos >= end_pos:
                 volatility_quantile_cache[pos] = np.nan
             else:
                 volatility_quantile_cache[pos] = calculate_quantile(
-                    natr_values[start:end], natr_values[pos]
+                    natr_values[start_pos:end_pos], natr_values[pos]
                 )
 
         return volatility_quantile_cache[pos]
index 40cb0d505d95dd2497e94e506a3c0aef79956bc9..cd6e2bfb7205997c16523fe0112cbce1b360c02a 100644 (file)
@@ -886,15 +886,13 @@ class QuickAdapterV3(IStrategy):
         if self.position_adjustment_enable:
             if exit_stage == start_partial_exit_stage:
                 return None
+            natr_ratio_percent = (
+                self.partial_exit_stages[exit_stage][0]
+                if exit_stage in self.partial_exit_stages
+                else 1.0
+            )
             secure_take_profit_distance = self.get_take_profit_distance(
-                df,
-                trade,
-                min(
-                    self.config.get("exit_pricing", {}).get(
-                        "trade_secure_percent", 0.2
-                    ),
-                    self.partial_exit_stages[start_partial_exit_stage][0] * 0.95,
-                ),
+                df, trade, natr_ratio_percent / 3
             )
             if isna(secure_take_profit_distance) or secure_take_profit_distance <= 0:
                 return None
@@ -920,12 +918,10 @@ class QuickAdapterV3(IStrategy):
                 if exit_stage < final_exit_stage:
                     trade.set_custom_data(key="exit_stage", value=final_exit_stage)
                 return f"secure_take_profit_{trade.trade_direction}_{final_exit_stage}"
-            if exit_stage == final_exit_stage:
-                natr_ratio_percent = 1.0
-            else:
+            if start_partial_exit_stage < exit_stage < final_exit_stage:
                 return None
         else:
-            if start_partial_exit_stage <= exit_stage <= end_partial_exit_stage:
+            if exit_stage in self.partial_exit_stages:
                 trade.set_custom_data(key="exit_stage", value=final_exit_stage)
             natr_ratio_percent = 0.7
 
index 3c42ffae4013a95d21798bc7ca90788c65fe9438..85a029e526298315dbfccbd3f80a2d0c1c2376c6 100644 (file)
@@ -432,13 +432,13 @@ def zigzag(
 
     def calculate_volatility_quantile(pos: int) -> float:
         if pos not in volatility_quantile_cache:
-            start = max(0, pos + 1 - natr_period)
-            end = min(pos + 1, n)
-            if start >= end:
+            start_pos = max(0, pos + 1 - natr_period)
+            end_pos = min(pos + 1, n)
+            if start_pos >= end_pos:
                 volatility_quantile_cache[pos] = np.nan
             else:
                 volatility_quantile_cache[pos] = calculate_quantile(
-                    natr_values[start:end], natr_values[pos]
+                    natr_values[start_pos:end_pos], natr_values[pos]
                 )
 
         return volatility_quantile_cache[pos]