From e6affcc23e01ecd8fe4a48ea41d7ca15b20f9727 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 29 May 2022 16:39:47 +0200 Subject: [PATCH] Move parameter file loading to hyper-mixin --- freqtrade/resolvers/strategy_resolver.py | 21 +-------------------- freqtrade/strategy/hyper.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/freqtrade/resolvers/strategy_resolver.py b/freqtrade/resolvers/strategy_resolver.py index 44d590b67..c63c133ce 100644 --- a/freqtrade/resolvers/strategy_resolver.py +++ b/freqtrade/resolvers/strategy_resolver.py @@ -47,26 +47,7 @@ class StrategyResolver(IResolver): strategy: IStrategy = StrategyResolver._load_strategy( strategy_name, config=config, extra_dir=config.get('strategy_path')) - - if strategy._ft_params_from_file: - # Set parameters from Hyperopt results file - params = strategy._ft_params_from_file - strategy.minimal_roi = params.get('roi', getattr(strategy, 'minimal_roi', {})) - - strategy.stoploss = params.get('stoploss', {}).get( - 'stoploss', getattr(strategy, 'stoploss', -0.1)) - trailing = params.get('trailing', {}) - strategy.trailing_stop = trailing.get( - 'trailing_stop', getattr(strategy, 'trailing_stop', False)) - strategy.trailing_stop_positive = trailing.get( - 'trailing_stop_positive', getattr(strategy, 'trailing_stop_positive', None)) - strategy.trailing_stop_positive_offset = trailing.get( - 'trailing_stop_positive_offset', - getattr(strategy, 'trailing_stop_positive_offset', 0)) - strategy.trailing_only_offset_is_reached = trailing.get( - 'trailing_only_offset_is_reached', - getattr(strategy, 'trailing_only_offset_is_reached', 0.0)) - + strategy.ft_load_hyper_params_from_file() # Set attributes # Check if we need to override configuration # (Attribute name, default, subkey) diff --git a/freqtrade/strategy/hyper.py b/freqtrade/strategy/hyper.py index bbd6ef5fe..c4119173b 100644 --- a/freqtrade/strategy/hyper.py +++ b/freqtrade/strategy/hyper.py @@ -85,6 +85,27 @@ class HyperStrategyMixin: return params + def ft_load_hyper_params_from_file(self) -> None: + """ Load Parameters from parameter file""" + if self._ft_params_from_file: + # Set parameters from Hyperopt results file + params = self._ft_params_from_file + self.minimal_roi = params.get('roi', getattr(self, 'minimal_roi', {})) + + self.stoploss = params.get('stoploss', {}).get( + 'stoploss', getattr(self, 'stoploss', -0.1)) + trailing = params.get('trailing', {}) + self.trailing_stop = trailing.get( + 'trailing_stop', getattr(self, 'trailing_stop', False)) + self.trailing_stop_positive = trailing.get( + 'trailing_stop_positive', getattr(self, 'trailing_stop_positive', None)) + self.trailing_stop_positive_offset = trailing.get( + 'trailing_stop_positive_offset', + getattr(self, 'trailing_stop_positive_offset', 0)) + self.trailing_only_offset_is_reached = trailing.get( + 'trailing_only_offset_is_reached', + getattr(self, 'trailing_only_offset_is_reached', 0.0)) + def ft_load_hyper_params(self, hyperopt: bool = False) -> None: """ Load Hyperoptable parameters