From 5dbfc92c5a75332d3a6a47bf1cbca0b15f44d3d7 Mon Sep 17 00:00:00 2001 From: mrpabloyeah Date: Sun, 14 Sep 2025 13:58:53 +0200 Subject: [PATCH] Add --enable-dynamic-pairlist option in backtesting --- docs/commands/backtesting.md | 8 +++++++- docs/commands/hyperopt.md | 2 +- docs/commands/lookahead-analysis.md | 8 +++++++- freqtrade/commands/arguments.py | 1 + freqtrade/commands/cli_options.py | 10 +++++++++- freqtrade/configuration/configuration.py | 8 +++++++- freqtrade/optimize/backtesting.py | 5 +---- 7 files changed, 33 insertions(+), 9 deletions(-) diff --git a/docs/commands/backtesting.md b/docs/commands/backtesting.md index 7082fb362..56d01f38f 100644 --- a/docs/commands/backtesting.md +++ b/docs/commands/backtesting.md @@ -10,6 +10,7 @@ usage: freqtrade backtesting [-h] [-v] [--no-color] [--logfile FILE] [-V] [--stake-amount STAKE_AMOUNT] [--fee FLOAT] [-p PAIRS [PAIRS ...]] [--eps] [--enable-protections] + [--enable-dynamic-pairlist] [--dry-run-wallet DRY_RUN_WALLET] [--timeframe-detail TIMEFRAME_DETAIL] [--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]] @@ -44,9 +45,14 @@ options: Allow buying the same pair multiple times (position stacking). --enable-protections, --enableprotections - Enable protections for backtesting.Will slow + Enable protections for backtesting. Will slow backtesting down by a considerable amount, but will include configured protections + --enable-dynamic-pairlist + Enables dynamic pairlisting in backtesting. The + pairlist will be generated for each new candle if + you're using a pairlist handler that supports this + feature, for example, ShuffleFilter. --dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET Starting balance, used for backtesting / hyperopt and dry-runs. diff --git a/docs/commands/hyperopt.md b/docs/commands/hyperopt.md index f1c8b28b5..933082b9d 100644 --- a/docs/commands/hyperopt.md +++ b/docs/commands/hyperopt.md @@ -44,7 +44,7 @@ options: Allow buying the same pair multiple times (position stacking). --enable-protections, --enableprotections - Enable protections for backtesting.Will slow + Enable protections for backtesting. Will slow backtesting down by a considerable amount, but will include configured protections --dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET diff --git a/docs/commands/lookahead-analysis.md b/docs/commands/lookahead-analysis.md index 880c41ce1..f7354d8ea 100644 --- a/docs/commands/lookahead-analysis.md +++ b/docs/commands/lookahead-analysis.md @@ -11,6 +11,7 @@ usage: freqtrade lookahead-analysis [-h] [-v] [--no-color] [--logfile FILE] [--stake-amount STAKE_AMOUNT] [--fee FLOAT] [-p PAIRS [PAIRS ...]] [--enable-protections] + [--enable-dynamic-pairlist] [--dry-run-wallet DRY_RUN_WALLET] [--timeframe-detail TIMEFRAME_DETAIL] [--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]] @@ -43,9 +44,14 @@ options: Limit command to these pairs. Pairs are space- separated. --enable-protections, --enableprotections - Enable protections for backtesting.Will slow + Enable protections for backtesting. Will slow backtesting down by a considerable amount, but will include configured protections + --enable-dynamic-pairlist + Enables dynamic pairlisting in backtesting. The + pairlist will be generated for each new candle if + you're using a pairlist handler that supports this + feature, for example, ShuffleFilter. --dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET Starting balance, used for backtesting / hyperopt and dry-runs. diff --git a/freqtrade/commands/arguments.py b/freqtrade/commands/arguments.py index 17d8f43d7..e4bdc170d 100755 --- a/freqtrade/commands/arguments.py +++ b/freqtrade/commands/arguments.py @@ -49,6 +49,7 @@ ARGS_BACKTEST = [ *ARGS_COMMON_OPTIMIZE, "position_stacking", "enable_protections", + "enable_dynamic_pairlist", "dry_run_wallet", "timeframe_detail", "strategy_list", diff --git a/freqtrade/commands/cli_options.py b/freqtrade/commands/cli_options.py index 62a007f59..fc613febe 100755 --- a/freqtrade/commands/cli_options.py +++ b/freqtrade/commands/cli_options.py @@ -184,12 +184,20 @@ AVAILABLE_CLI_OPTIONS = { "enable_protections": Arg( "--enable-protections", "--enableprotections", - help="Enable protections for backtesting." + help="Enable protections for backtesting. " "Will slow backtesting down by a considerable amount, but will include " "configured protections", action="store_true", default=False, ), + "enable_dynamic_pairlist": Arg( + "--enable-dynamic-pairlist", + help="Enables dynamic pairlisting in backtesting. " + "The pairlist will be generated for each new candle if you're using a " + "pairlist handler that supports this feature, for example, ShuffleFilter.", + action="store_true", + default=False, + ), "strategy_list": Arg( "--strategy-list", help="Provide a space-separated list of strategies to backtest. " diff --git a/freqtrade/configuration/configuration.py b/freqtrade/configuration/configuration.py index 7bf448335..cc40edef1 100644 --- a/freqtrade/configuration/configuration.py +++ b/freqtrade/configuration/configuration.py @@ -256,7 +256,13 @@ class Configuration: self._args_to_config( config, argname="enable_protections", - logstring="Parameter --enable-protections detected, enabling Protections. ...", + logstring="Parameter --enable-protections detected, enabling Protections ...", + ) + + self._args_to_config( + config, + argname="enable_dynamic_pairlist", + logstring="Parameter --enable-dynamic-pairlist detected, enabling dynamic pairlist ...", ) if self.args.get("max_open_trades"): diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index d6336b567..5ae91ee30 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -173,7 +173,6 @@ class Backtesting: self.disable_database_use() self.init_backtest_detail() self.pairlists = PairListManager(self.exchange, self.config, self.dataprovider) - self.dynamic_pairlist = False self._validate_pairlists_for_backtesting() self.dataprovider.add_pairlisthandler(self.pairlists) @@ -212,6 +211,7 @@ class Backtesting: self._can_short = self.trading_mode != TradingMode.SPOT self._position_stacking: bool = self.config.get("position_stacking", False) self.enable_protections: bool = self.config.get("enable_protections", False) + self.dynamic_pairlist: bool = self.config.get("enable_dynamic_pairlist", False) migrate_data(config, self.exchange) self.init_backtest() @@ -227,9 +227,6 @@ class Backtesting: "PrecisionFilter not allowed for backtesting multiple strategies." ) - if "ShuffleFilter" in self.pairlists.name_list: - self.dynamic_pairlist = True - def log_once(self, msg: str) -> None: """ Partial reimplementation of log_once from the Login mixin.