Merge pull request #2308 from hroff-1902/hyperopt-config
Allow use of config in custom hyperopt methods
This commit is contained in:
commit
ed10048394
@ -36,6 +36,12 @@ class IHyperOpt(ABC):
|
|||||||
"""
|
"""
|
||||||
ticker_interval: str
|
ticker_interval: str
|
||||||
|
|
||||||
|
def __init__(self, config: dict) -> None:
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
# Assign ticker_interval to be used in hyperopt
|
||||||
|
IHyperOpt.ticker_interval = str(config['ticker_interval'])
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame:
|
def populate_indicators(dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||||
|
@ -34,9 +34,6 @@ class HyperOptResolver(IResolver):
|
|||||||
self.hyperopt = self._load_hyperopt(hyperopt_name, config,
|
self.hyperopt = self._load_hyperopt(hyperopt_name, config,
|
||||||
extra_dir=config.get('hyperopt_path'))
|
extra_dir=config.get('hyperopt_path'))
|
||||||
|
|
||||||
# Assign ticker_interval to be used in hyperopt
|
|
||||||
IHyperOpt.ticker_interval = str(config['ticker_interval'])
|
|
||||||
|
|
||||||
if not hasattr(self.hyperopt, 'populate_buy_trend'):
|
if not hasattr(self.hyperopt, 'populate_buy_trend'):
|
||||||
logger.warning("Hyperopt class does not provide populate_buy_trend() method. "
|
logger.warning("Hyperopt class does not provide populate_buy_trend() method. "
|
||||||
"Using populate_buy_trend from the strategy.")
|
"Using populate_buy_trend from the strategy.")
|
||||||
@ -65,7 +62,7 @@ class HyperOptResolver(IResolver):
|
|||||||
abs_paths.insert(0, Path(extra_dir).resolve())
|
abs_paths.insert(0, Path(extra_dir).resolve())
|
||||||
|
|
||||||
hyperopt = self._load_object(paths=abs_paths, object_type=IHyperOpt,
|
hyperopt = self._load_object(paths=abs_paths, object_type=IHyperOpt,
|
||||||
object_name=hyperopt_name)
|
object_name=hyperopt_name, kwargs={'config': config})
|
||||||
if hyperopt:
|
if hyperopt:
|
||||||
return hyperopt
|
return hyperopt
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
|
@ -153,7 +153,7 @@ def test_hyperoptresolver(mocker, default_conf, caplog) -> None:
|
|||||||
delattr(hyperopts, 'populate_sell_trend')
|
delattr(hyperopts, 'populate_sell_trend')
|
||||||
mocker.patch(
|
mocker.patch(
|
||||||
'freqtrade.resolvers.hyperopt_resolver.HyperOptResolver._load_hyperopt',
|
'freqtrade.resolvers.hyperopt_resolver.HyperOptResolver._load_hyperopt',
|
||||||
MagicMock(return_value=hyperopts)
|
MagicMock(return_value=hyperopts(default_conf))
|
||||||
)
|
)
|
||||||
x = HyperOptResolver(default_conf, ).hyperopt
|
x = HyperOptResolver(default_conf, ).hyperopt
|
||||||
assert not hasattr(x, 'populate_buy_trend')
|
assert not hasattr(x, 'populate_buy_trend')
|
||||||
|
Loading…
Reference in New Issue
Block a user