From d64ac9f347f062bc22a8e9efc17e8ab24bd4e2ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 19 Mar 2025 02:30:03 +0100 Subject: [PATCH] refactor(qav3): code cleanups MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../user_data/strategies/QuickAdapterV3.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/quickadapter/user_data/strategies/QuickAdapterV3.py b/quickadapter/user_data/strategies/QuickAdapterV3.py index 2b98df4..0451999 100644 --- a/quickadapter/user_data/strategies/QuickAdapterV3.py +++ b/quickadapter/user_data/strategies/QuickAdapterV3.py @@ -413,11 +413,10 @@ class QuickAdapterV3(IStrategy): if not entry_natr: return 0.0 last_natr = df["natr_ratio_labeling_window"].iloc[-1] - return ( - trade.open_rate - * fmean([entry_natr, last_natr]) - * self.trailing_stoploss_natr_ratio - ) + if not last_natr: + return 0.0 + natr = fmean([entry_natr, last_natr]) + return trade.open_rate * natr * self.trailing_stoploss_natr_ratio def custom_stoploss( self, @@ -615,12 +614,14 @@ def top_change_percent(dataframe: DataFrame, period: int) -> Series: :param period: int The period size to look back :return: Series The percentage change series """ + if period < 0: + raise ValueError("period must be greater than or equal to 0") if period == 0: previous_close = dataframe["close"].shift(1) - return (dataframe["close"] - previous_close) / previous_close else: - previous_close_max = dataframe["close"].rolling(period).max().shift(1) - return (dataframe["close"] - previous_close_max) / previous_close_max + previous_close = dataframe["close"].rolling(period).max().shift(1) + + return (dataframe["close"] - previous_close) / previous_close # VWAP bands -- 2.43.0