From 81440b25a4b8281f2a486565fe828b91ee2350e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 29 Jul 2025 15:52:14 +0200 Subject: [PATCH] perf(qav3): use less noise sensitive trade entries thresholding MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../freqaimodels/QuickAdapterRegressorV3.py | 46 ++----------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index 0b1dcac..8eea7ab 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -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. -- 2.43.0