diff --git a/freqtrade/configuration/arguments.py b/freqtrade/configuration/arguments.py index b6deb2451..f72f785a0 100644 --- a/freqtrade/configuration/arguments.py +++ b/freqtrade/configuration/arguments.py @@ -223,10 +223,10 @@ AVAILABLE_CLI_OPTIONS = { metavar='INT', default=1, ), - "hyperopt_clean_state": Arg( - "--clean", - help="Remove temporary hyperopt files (should be used when the custom hyperopt file " - "was changed, or when changing the arguments for --min-trades or spaces.", + "hyperopt_continue": Arg( + "--continue", + help="Continue hyperopt from previous runs. " + "By default, temporary files will be removed and hyperopt will start from scratch.", default=False, action='store_true', ), @@ -325,7 +325,7 @@ ARGS_BACKTEST = ARGS_COMMON_OPTIMIZE + ["position_stacking", "use_max_market_pos ARGS_HYPEROPT = ARGS_COMMON_OPTIMIZE + ["hyperopt", "position_stacking", "epochs", "spaces", "use_max_market_positions", "print_all", "hyperopt_jobs", "hyperopt_random_state", "hyperopt_min_trades", - "hyperopt_clean_state", "loss_function"] + "hyperopt_continue", "loss_function"] ARGS_EDGE = ARGS_COMMON_OPTIMIZE + ["stoploss_range"] diff --git a/freqtrade/configuration/configuration.py b/freqtrade/configuration/configuration.py index a8a45653e..cb8f77234 100644 --- a/freqtrade/configuration/configuration.py +++ b/freqtrade/configuration/configuration.py @@ -285,8 +285,8 @@ class Configuration(object): self._args_to_config(config, argname='hyperopt_min_trades', logstring='Parameter --min-trades detected: {}') - self._args_to_config(config, argname='hyperopt_clean_state', - logstring='Removing hyperopt temp files') + self._args_to_config(config, argname='hyperopt_continue', + logstring='Hyperopt continue: {}') self._args_to_config(config, argname='loss_function', logstring='Using loss function: {}') diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index e041554dc..fece7d9d8 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -65,8 +65,11 @@ class Hyperopt(Backtesting): # Note, this is ratio. 3.85 stated above means 385Σ%. self.expected_max_profit = 3.0 - if self.config.get('hyperopt_clean_state'): + if not self.config.get('hyperopt_continue'): self.clean_hyperopt() + else: + logger.info("Continuing on previous hyperopt results.") + # Previous evaluations self.trials_file = TRIALSDATA_PICKLE self.trials: List = [] @@ -99,6 +102,7 @@ class Hyperopt(Backtesting): else: logger.debug('Ignoring max_open_trades (--disable-max-market-positions was used) ...') self.max_open_trades = 0 + self.position_stacking = self.config.get('position_stacking', False), def clean_hyperopt(self): """ @@ -231,7 +235,7 @@ class Hyperopt(Backtesting): 'stake_amount': self.config['stake_amount'], 'processed': processed, 'max_open_trades': self.max_open_trades, - 'position_stacking': self.config.get('position_stacking', False), + 'position_stacking': self.position_stacking, 'start_date': min_date, 'end_date': max_date, } diff --git a/freqtrade/tests/optimize/test_hyperopt.py b/freqtrade/tests/optimize/test_hyperopt.py index aae3405ad..794cba973 100644 --- a/freqtrade/tests/optimize/test_hyperopt.py +++ b/freqtrade/tests/optimize/test_hyperopt.py @@ -418,6 +418,7 @@ def test_start_calls_optimizer(mocker, default_conf, caplog) -> None: assert hasattr(hyperopt, "advise_buy") assert hasattr(hyperopt, "max_open_trades") assert hyperopt.max_open_trades == default_conf['max_open_trades'] + assert hasattr(hyperopt, "position_stacking") def test_format_results(hyperopt): @@ -569,8 +570,24 @@ def test_clean_hyperopt(mocker, default_conf, caplog): }) mocker.patch("freqtrade.optimize.hyperopt.Path.is_file", MagicMock(return_value=True)) unlinkmock = mocker.patch("freqtrade.optimize.hyperopt.Path.unlink", MagicMock()) - hyp = Hyperopt(default_conf) + Hyperopt(default_conf) - hyp.clean_hyperopt() assert unlinkmock.call_count == 2 assert log_has(f"Removing `{TICKERDATA_PICKLE}`.", caplog.record_tuples) + + +def test_continue_hyperopt(mocker, default_conf, caplog): + patch_exchange(mocker) + default_conf.update({'config': 'config.json.example', + 'epochs': 1, + 'timerange': None, + 'spaces': 'all', + 'hyperopt_jobs': 1, + 'hyperopt_continue': True + }) + mocker.patch("freqtrade.optimize.hyperopt.Path.is_file", MagicMock(return_value=True)) + unlinkmock = mocker.patch("freqtrade.optimize.hyperopt.Path.unlink", MagicMock()) + Hyperopt(default_conf) + + assert unlinkmock.call_count == 0 + assert log_has(f"Continuing on previous hyperopt results.", caplog.record_tuples)