From 0a0834e5207b0dbb6323fb2d953bbf70dcbf759a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 19 May 2025 11:22:07 +0200 Subject: [PATCH] fix(qav3): avoid log usage on values that can be close to zero MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../freqaimodels/QuickAdapterRegressorV3.py | 31 +++++++++---------- .../user_data/strategies/QuickAdapterV3.py | 2 +- quickadapter/user_data/strategies/Utils.py | 31 +++++++++---------- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index ba3d4a5..12f765c 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -851,7 +851,7 @@ class TrendDirection(IntEnum): def zigzag( df: pd.DataFrame, natr_period: int = 14, - natr_ratio: float = 1.0, + natr_ratio: float = 0.12125, confirmation_window: int = 3, initial_depth: int = 12, ) -> tuple[list[int], list[float], list[int]]: @@ -1042,16 +1042,16 @@ def zigzag( significant_move_away_ok = False if direction == TrendDirection.DOWN: if np.any( - np.log(next_lows) - < np.log(highs[candidate_pivot_pos]) - + np.log(1 - thresholds[candidate_pivot_pos] * move_away_ratio) + next_lows + < highs[candidate_pivot_pos] + * (1 - thresholds[candidate_pivot_pos] * move_away_ratio) ): significant_move_away_ok = True elif direction == TrendDirection.UP: if np.any( - np.log(next_highs) - > np.log(lows[candidate_pivot_pos]) - + np.log(1 + thresholds[candidate_pivot_pos] * move_away_ratio) + next_highs + > lows[candidate_pivot_pos] + * (1 + thresholds[candidate_pivot_pos] * move_away_ratio) ): significant_move_away_ok = True return significant_move_away_ok @@ -1071,10 +1071,13 @@ def zigzag( initial_move_from_high = (initial_high - current_low) / initial_high initial_move_from_low = (current_high - initial_low) / initial_low - if ( + is_initial_high_move_significant = ( initial_move_from_high >= thresholds[initial_high_pos] - and initial_move_from_low >= thresholds[initial_low_pos] - ): + ) + is_initial_low_move_significant = ( + initial_move_from_low >= thresholds[initial_low_pos] + ) + if is_initial_high_move_significant and is_initial_low_move_significant: if initial_move_from_high > initial_move_from_low: if is_reversal_confirmed( initial_high_pos, initial_high_pos, TrendDirection.DOWN @@ -1090,17 +1093,13 @@ def zigzag( state = TrendDirection.UP break else: - if initial_move_from_high >= thresholds[ - initial_high_pos - ] and is_reversal_confirmed( + if is_initial_high_move_significant and is_reversal_confirmed( initial_high_pos, initial_high_pos, TrendDirection.DOWN ): add_pivot(initial_high_pos, initial_high, TrendDirection.UP) state = TrendDirection.DOWN break - elif initial_move_from_low >= thresholds[ - initial_low_pos - ] and is_reversal_confirmed( + elif is_initial_low_move_significant and is_reversal_confirmed( initial_low_pos, initial_low_pos, TrendDirection.UP ): add_pivot(initial_low_pos, initial_low, TrendDirection.DOWN) diff --git a/quickadapter/user_data/strategies/QuickAdapterV3.py b/quickadapter/user_data/strategies/QuickAdapterV3.py index d86d17e..0b203fe 100644 --- a/quickadapter/user_data/strategies/QuickAdapterV3.py +++ b/quickadapter/user_data/strategies/QuickAdapterV3.py @@ -58,7 +58,7 @@ class QuickAdapterV3(IStrategy): INTERFACE_VERSION = 3 def version(self) -> str: - return "3.3.39" + return "3.3.40" timeframe = "5m" diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index 440edcd..eb47cc1 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -348,7 +348,7 @@ class TrendDirection(IntEnum): def zigzag( df: pd.DataFrame, natr_period: int = 14, - natr_ratio: float = 1.0, + natr_ratio: float = 0.12125, confirmation_window: int = 3, initial_depth: int = 12, ) -> tuple[list[int], list[float], list[int]]: @@ -539,16 +539,16 @@ def zigzag( significant_move_away_ok = False if direction == TrendDirection.DOWN: if np.any( - np.log(next_lows) - < np.log(highs[candidate_pivot_pos]) - + np.log(1 - thresholds[candidate_pivot_pos] * move_away_ratio) + next_lows + < highs[candidate_pivot_pos] + * (1 - thresholds[candidate_pivot_pos] * move_away_ratio) ): significant_move_away_ok = True elif direction == TrendDirection.UP: if np.any( - np.log(next_highs) - > np.log(lows[candidate_pivot_pos]) - + np.log(1 + thresholds[candidate_pivot_pos] * move_away_ratio) + next_highs + > lows[candidate_pivot_pos] + * (1 + thresholds[candidate_pivot_pos] * move_away_ratio) ): significant_move_away_ok = True return significant_move_away_ok @@ -568,10 +568,13 @@ def zigzag( initial_move_from_high = (initial_high - current_low) / initial_high initial_move_from_low = (current_high - initial_low) / initial_low - if ( + is_initial_high_move_significant = ( initial_move_from_high >= thresholds[initial_high_pos] - and initial_move_from_low >= thresholds[initial_low_pos] - ): + ) + is_initial_low_move_significant = ( + initial_move_from_low >= thresholds[initial_low_pos] + ) + if is_initial_high_move_significant and is_initial_low_move_significant: if initial_move_from_high > initial_move_from_low: if is_reversal_confirmed( initial_high_pos, initial_high_pos, TrendDirection.DOWN @@ -587,17 +590,13 @@ def zigzag( state = TrendDirection.UP break else: - if initial_move_from_high >= thresholds[ - initial_high_pos - ] and is_reversal_confirmed( + if is_initial_high_move_significant and is_reversal_confirmed( initial_high_pos, initial_high_pos, TrendDirection.DOWN ): add_pivot(initial_high_pos, initial_high, TrendDirection.UP) state = TrendDirection.DOWN break - elif initial_move_from_low >= thresholds[ - initial_low_pos - ] and is_reversal_confirmed( + elif is_initial_low_move_significant and is_reversal_confirmed( initial_low_pos, initial_low_pos, TrendDirection.UP ): add_pivot(initial_low_pos, initial_low, TrendDirection.DOWN) -- 2.43.0