From f67071e9cb66163eeb7c5b1de796cb4405a770c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 23 May 2025 14:02:37 +0200 Subject: [PATCH] refactor(qav3): align pivot confirmation checks behavior MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../freqaimodels/QuickAdapterRegressorV3.py | 39 +++++-------------- .../user_data/strategies/QuickAdapterV3.py | 2 +- quickadapter/user_data/strategies/Utils.py | 37 ++++-------------- 3 files changed, 18 insertions(+), 60 deletions(-) diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index eba8d66..fdb42b2 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -45,7 +45,7 @@ class QuickAdapterRegressorV3(BaseRegressionModel): https://github.com/sponsors/robcaulk """ - version = "3.7.57" + version = "3.7.58" @cached_property def _optuna_config(self) -> dict: @@ -934,9 +934,7 @@ def zigzag( ) -> int: quantile = volatility_quantile(pos) if np.isnan(quantile): - return np.clip( - round(np.median([min_window, max_window]), min_window, max_window) - ).astype(int) + return int(round(np.median([min_window, max_window]))) return np.clip( round(max_window - (max_window - min_window) * quantile), @@ -944,38 +942,19 @@ def zigzag( max_window, ).astype(int) - def calculate_depth_factor( - pos: int, - min_factor: float = 0.5, - max_factor: float = 1.5, - ) -> float: - quantile = volatility_quantile(pos) - if np.isnan(quantile): - return np.median([min_factor, max_factor]) - - return max_factor - (max_factor - min_factor) * quantile - def calculate_depth( pos: int, min_depth: int = 6, - max_depth: int = 36, + max_depth: int = 24, ) -> int: - if not pivots_indices: - return min_depth - depth_factor = calculate_depth_factor(pos) - if len(pivots_indices) < 2: - return np.clip( - round(np.median([min_depth, max_depth]) * depth_factor), - min_depth, - max_depth, - ).astype(int) - - previous_periods = np.diff(pivots_indices[-3:]) - weights = np.linspace(0.5, 1.5, len(previous_periods)) - average_period = np.average(previous_periods, weights=weights) + quantile = volatility_quantile(pos) + if np.isnan(quantile): + return int(round(np.median([min_depth, max_depth]))) return np.clip( - round(average_period * depth_factor), min_depth, max_depth + round(max_depth - (max_depth - min_depth) * quantile), + min_depth, + max_depth, ).astype(int) def calculate_min_slope_strength( diff --git a/quickadapter/user_data/strategies/QuickAdapterV3.py b/quickadapter/user_data/strategies/QuickAdapterV3.py index 14b9a11..ff28dea 100644 --- a/quickadapter/user_data/strategies/QuickAdapterV3.py +++ b/quickadapter/user_data/strategies/QuickAdapterV3.py @@ -60,7 +60,7 @@ class QuickAdapterV3(IStrategy): INTERFACE_VERSION = 3 def version(self) -> str: - return "3.3.57" + return "3.3.58" timeframe = "5m" diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index 6b0e839..0d7809c 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -418,9 +418,7 @@ def zigzag( ) -> int: quantile = volatility_quantile(pos) if np.isnan(quantile): - return np.clip( - round(np.median([min_window, max_window])), min_window, max_window - ).astype(int) + return int(round(np.median([min_window, max_window]))) return np.clip( round(max_window - (max_window - min_window) * quantile), @@ -428,38 +426,19 @@ def zigzag( max_window, ).astype(int) - def calculate_depth_factor( - pos: int, - min_factor: float = 0.5, - max_factor: float = 1.5, - ) -> float: - quantile = volatility_quantile(pos) - if np.isnan(quantile): - return np.median([min_factor, max_factor]) - - return max_factor - (max_factor - min_factor) * quantile - def calculate_depth( pos: int, min_depth: int = 6, - max_depth: int = 36, + max_depth: int = 24, ) -> int: - if not pivots_indices: - return min_depth - depth_factor = calculate_depth_factor(pos) - if len(pivots_indices) < 2: - return np.clip( - round(np.median([min_depth, max_depth]) * depth_factor), - min_depth, - max_depth, - ).astype(int) - - previous_periods = np.diff(pivots_indices[-3:]) - weights = np.linspace(0.5, 1.5, len(previous_periods)) - average_period = np.average(previous_periods, weights=weights) + quantile = volatility_quantile(pos) + if np.isnan(quantile): + return int(round(np.median([min_depth, max_depth]))) return np.clip( - round(average_period * depth_factor), min_depth, max_depth + round(max_depth - (max_depth - min_depth) * quantile), + min_depth, + max_depth, ).astype(int) def calculate_min_slope_strength( -- 2.43.0