From d33e931a0d092a2d3377834ddd96f18261dc69ad Mon Sep 17 00:00:00 2001 From: viotemp1 Date: Sat, 17 May 2025 16:23:25 +0300 Subject: [PATCH] early stop - replace values lower than 20 with 20 and display a warning. --- docs/hyperopt.md | 2 +- freqtrade/configuration/configuration.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/hyperopt.md b/docs/hyperopt.md index 0c1a53421..af5ea9d2c 100644 --- a/docs/hyperopt.md +++ b/docs/hyperopt.md @@ -490,7 +490,7 @@ freqtrade hyperopt --config config.json --hyperopt-loss --str ``` The `-e` option will set how many evaluations hyperopt will do. Since hyperopt uses Bayesian search, running too many epochs at once may not produce greater results. Experience has shown that best results are usually not improving much after 500-1000 epochs. -The `--early-stop` option will set after how many epochs with no improvements hyperopt will stop. A good value is 20-30% of the total epochs. Early stop is by default disabled (`--early-stop=0`) +The `--early-stop` option will set after how many epochs with no improvements hyperopt will stop. A good value is 20-30% of the total epochs. Any value greater than 0 and lower than 20 it will be replaced by 20. Early stop is by default disabled (`--early-stop=0`) Doing multiple runs (executions) with a few 1000 epochs and different random state will most likely produce different results. diff --git a/freqtrade/configuration/configuration.py b/freqtrade/configuration/configuration.py index 999b31fe5..b5b05a91f 100644 --- a/freqtrade/configuration/configuration.py +++ b/freqtrade/configuration/configuration.py @@ -334,8 +334,16 @@ class Configuration: ("print_all", "Parameter --print-all detected ..."), ] self._args_to_config_loop(config, configurations) - if self.args.get("early_stop", 0) > 0: - config.update({"early_stop": self.args["early_stop"]}) + es_epochs = self.args.get("early_stop", 0) + if es_epochs > 0: + if es_epochs < 20: + logger.warning( + f"Early stop epochs {es_epochs} lower than 20. " + f"It will be replaced with 20." + ) + config.update({"early_stop": 20}) + else: + config.update({"early_stop": self.args["early_stop"]}) logger.info( f"Parameter --early-stop detected ... Will early stop hyperopt if no improvement " f"after {self.args.get('early_stop')} epochs ..."