Load parameters from file

This commit is contained in:
Matthias 2021-06-29 07:07:34 +02:00
parent 8ca0076332
commit a2ccc1526e
3 changed files with 18 additions and 1 deletions

View File

@ -53,6 +53,21 @@ class StrategyResolver(IResolver):
) )
strategy.timeframe = strategy.ticker_interval strategy.timeframe = strategy.ticker_interval
if strategy._ft_params_from_file:
# Set parameters from Hyperopt results file
params = strategy._ft_params_from_file
strategy.minimal_roi = params.get('roi', strategy.minimal_roi)
strategy.stoploss = params.get('stoploss', {}).get('stoploss', strategy.stoploss)
trailing = params.get('trailing', {})
strategy.trailing_stop = trailing.get('trailing_stop', strategy.trailing_stop)
strategy.trailing_stop_positive = trailing.get('trailing_stop_positive',
strategy.trailing_stop_positive)
strategy.trailing_stop_positive_offset = trailing.get(
'trailing_stop_positive_offset', strategy.trailing_stop_positive_offset)
strategy.trailing_only_offset_is_reached = trailing.get(
'trailing_only_offset_is_reached', strategy.trailing_only_offset_is_reached)
# Set attributes # Set attributes
# Check if we need to override configuration # Check if we need to override configuration
# (Attribute name, default, subkey) # (Attribute name, default, subkey)

View File

@ -309,6 +309,7 @@ class HyperStrategyMixin(object):
""" """
params = self.load_params_from_file() params = self.load_params_from_file()
params = params.get('params', {}) params = params.get('params', {})
self._ft_params_from_file = params
buy_params = deep_merge_dicts(params.get('buy', {}), getattr(self, 'buy_params', None)) buy_params = deep_merge_dicts(params.get('buy', {}), getattr(self, 'buy_params', None))
sell_params = deep_merge_dicts(params.get('sell', {}), getattr(self, 'sell_params', None)) sell_params = deep_merge_dicts(params.get('sell', {}), getattr(self, 'sell_params', None))
@ -324,7 +325,7 @@ class HyperStrategyMixin(object):
if filename.is_file(): if filename.is_file():
logger.info(f"Loading parameters from file {filename}") logger.info(f"Loading parameters from file {filename}")
params = json_load(filename.open('r')) params = json_load(filename.open('r'))
if params.get('strategy_name') != self.get_strategy_name(): if params.get('strategy_name') != self.__class__.__name__:
raise OperationalException('Invalid parameter file provided') raise OperationalException('Invalid parameter file provided')
return params return params
logger.info("Found no parameter file.") logger.info("Found no parameter file.")

View File

@ -62,6 +62,7 @@ class IStrategy(ABC, HyperStrategyMixin):
_populate_fun_len: int = 0 _populate_fun_len: int = 0
_buy_fun_len: int = 0 _buy_fun_len: int = 0
_sell_fun_len: int = 0 _sell_fun_len: int = 0
_ft_params_from_file: Dict = {}
# associated minimal roi # associated minimal roi
minimal_roi: Dict minimal_roi: Dict