From cb4da0c950dbc0dc587c6d01993ff5e79e4efc66 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 26 Apr 2025 23:48:55 +0200 Subject: [PATCH] refactor(qav3): cleanup zigzag() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../freqaimodels/QuickAdapterRegressorV3.py | 17 +++++++++-------- quickadapter/user_data/strategies/Utils.py | 17 +++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index d13441c..f3b1c2e 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -898,20 +898,21 @@ def zigzag( return [], [], [] for i in range(i + 1, len(df)): + last_pivot_val = pivots_values[-1] if state == 1: - if highs[i] > pivots_values[-1]: + if highs[i] > last_pivot_val: update_last_pivot(i, highs[i], 1) - elif (pivots_values[-1] - lows[i]) / pivots_values[-1] >= thresholds[ - i - ] and (i - last_pivot_pos) >= depth: + elif (last_pivot_val - lows[i]) / last_pivot_val >= thresholds[i] and ( + i - last_pivot_pos + ) >= depth: add_pivot(i, lows[i], -1) state = -1 elif state == -1: - if lows[i] < pivots_values[-1]: + if lows[i] < last_pivot_val: update_last_pivot(i, lows[i], -1) - elif (highs[i] - pivots_values[-1]) / pivots_values[-1] >= thresholds[ - i - ] and (i - last_pivot_pos) >= depth: + elif (highs[i] - last_pivot_val) / last_pivot_val >= thresholds[i] and ( + i - last_pivot_pos + ) >= depth: add_pivot(i, highs[i], 1) state = 1 diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index 3d44ae9..7d13607 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -353,20 +353,21 @@ def zigzag( return [], [], [] for i in range(i + 1, len(df)): + last_pivot_val = pivots_values[-1] if state == 1: - if highs[i] > pivots_values[-1]: + if highs[i] > last_pivot_val: update_last_pivot(i, highs[i], 1) - elif (pivots_values[-1] - lows[i]) / pivots_values[-1] >= thresholds[ - i - ] and (i - last_pivot_pos) >= depth: + elif (last_pivot_val - lows[i]) / last_pivot_val >= thresholds[i] and ( + i - last_pivot_pos + ) >= depth: add_pivot(i, lows[i], -1) state = -1 elif state == -1: - if lows[i] < pivots_values[-1]: + if lows[i] < last_pivot_val: update_last_pivot(i, lows[i], -1) - elif (highs[i] - pivots_values[-1]) / pivots_values[-1] >= thresholds[ - i - ] and (i - last_pivot_pos) >= depth: + elif (highs[i] - last_pivot_val) / last_pivot_val >= thresholds[i] and ( + i - last_pivot_pos + ) >= depth: add_pivot(i, highs[i], 1) state = 1 -- 2.43.0