]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
perf(qav3): use less noise sensitive trade entries thresholding
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 29 Jul 2025 13:52:14 +0000 (15:52 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 29 Jul 2025 13:52:14 +0000 (15:52 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py

index 0b1dcac5de592dbdb08dc01e543b77b755c0e1f2..8eea7aba8da57c71deada9bf00eace2bc56fd71e 100644 (file)
@@ -518,17 +518,15 @@ class QuickAdapterRegressorV3(BaseRegressionModel):
         fit_live_predictions_candles: int,
         label_period_candles: int,
     ) -> tuple[float, float]:
-        temperature = float(
-            self.freqai_info.get("prediction_thresholds_temperature", 300.0)
-        )
+        q = float(self.freqai_info.get("prediction_thresholds_quantile", 0.95))
         extrema = pred_df.get(EXTREMA_COLUMN).iloc[
             -(
                 max(2, int(fit_live_predictions_candles / label_period_candles))
                 * label_period_candles
             ) :
         ]
-        min_pred = smoothed_min(extrema, temperature=temperature)
-        max_pred = smoothed_max(extrema, temperature=temperature)
+        min_pred = extrema.quantile(q=1 - q)
+        max_pred = extrema.quantile(q=q)
         return min_pred, max_pred
 
     def get_multi_objective_study_best_trial(
@@ -1700,44 +1698,6 @@ def label_objective(
     return np.median(pivots_thresholds), len(pivots_values)
 
 
-def smoothed_max(series: pd.Series, temperature=1.0) -> float:
-    data_array = series.to_numpy()
-    if data_array.size == 0:
-        return np.nan
-    if temperature < 0:
-        raise ValueError("temperature must be non-negative")
-    if np.isclose(temperature, 0):
-        return data_array.max()
-    return sp.special.logsumexp(temperature * data_array) / temperature
-
-
-def smoothed_min(series: pd.Series, temperature=1.0) -> float:
-    data_array = series.to_numpy()
-    if data_array.size == 0:
-        return np.nan
-    if temperature < 0:
-        raise ValueError("temperature must be non-negative")
-    if np.isclose(temperature, 0):
-        return data_array.min()
-    return -sp.special.logsumexp(-temperature * data_array) / temperature
-
-
-def boltzmann_operator(series: pd.Series, alpha: float) -> float:
-    """
-    Compute the Boltzmann operator of a series with parameter alpha.
-    """
-    data_array = series.to_numpy()
-    if data_array.size == 0:
-        return np.nan
-    if alpha == 0:
-        return np.mean(data_array)
-    scaled_data = alpha * data_array
-    shifted_exponentials = np.exp(scaled_data - np.max(scaled_data))
-    numerator = np.sum(data_array * shifted_exponentials)
-    denominator = np.sum(shifted_exponentials)
-    return numerator / denominator
-
-
 def round_to_nearest_int(value: float, step: int) -> int:
     """
     Round a value to the nearest multiple of a given step.