[SQUASH] Make skopt imports optional.
This commit is contained in:
parent
11689100e7
commit
fd45dfd894
@ -3,9 +3,12 @@ HyperOptAuto class.
|
||||
This module implements a convenience auto-hyperopt class, which can be used together with strategies
|
||||
that implement IHyperStrategy interface.
|
||||
"""
|
||||
from contextlib import suppress
|
||||
from typing import Any, Callable, Dict, List
|
||||
|
||||
from pandas import DataFrame
|
||||
from skopt.space import Categorical, Dimension, Integer, Real # noqa
|
||||
with suppress(ImportError):
|
||||
from skopt.space import Dimension
|
||||
|
||||
from freqtrade.optimize.hyperopt_interface import IHyperOpt
|
||||
|
||||
@ -57,23 +60,23 @@ class HyperOptAuto(IHyperOpt):
|
||||
else:
|
||||
return self._get_func(fallback_method_name)()
|
||||
|
||||
def indicator_space(self) -> List[Dimension]:
|
||||
def indicator_space(self) -> List['Dimension']:
|
||||
return self._get_indicator_space('buy', 'indicator_space')
|
||||
|
||||
def sell_indicator_space(self) -> List[Dimension]:
|
||||
def sell_indicator_space(self) -> List['Dimension']:
|
||||
return self._get_indicator_space('sell', 'sell_indicator_space')
|
||||
|
||||
def generate_roi_table(self, params: Dict) -> Dict[int, float]:
|
||||
return self._get_func('generate_roi_table')(params)
|
||||
|
||||
def roi_space(self) -> List[Dimension]:
|
||||
def roi_space(self) -> List['Dimension']:
|
||||
return self._get_func('roi_space')()
|
||||
|
||||
def stoploss_space(self) -> List[Dimension]:
|
||||
def stoploss_space(self) -> List['Dimension']:
|
||||
return self._get_func('stoploss_space')()
|
||||
|
||||
def generate_trailing_params(self, params: Dict) -> Dict:
|
||||
return self._get_func('generate_trailing_params')(params)
|
||||
|
||||
def trailing_space(self) -> List[Dimension]:
|
||||
def trailing_space(self) -> List['Dimension']:
|
||||
return self._get_func('trailing_space')()
|
||||
|
@ -2,8 +2,10 @@
|
||||
IHyperStrategy interface, hyperoptable Parameter class.
|
||||
This module defines a base class for auto-hyperoptable strategies.
|
||||
"""
|
||||
from contextlib import suppress
|
||||
from typing import Iterator, Tuple, Any, Optional, Sequence, Union
|
||||
|
||||
with suppress(ImportError):
|
||||
from skopt.space import Integer, Real, Categorical
|
||||
|
||||
from freqtrade.exceptions import OperationalException
|
||||
@ -38,7 +40,7 @@ class BaseParameter(object):
|
||||
def __repr__(self):
|
||||
return f'{self.__class__.__name__}({self.value})'
|
||||
|
||||
def get_space(self, name: str) -> Union[Integer, Real, Categorical]:
|
||||
def get_space(self, name: str) -> Union['Integer', 'Real', 'Categorical']:
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
@ -62,7 +64,7 @@ class IntParameter(BaseParameter):
|
||||
raise OperationalException('IntParameter space must be [min, max]')
|
||||
super().__init__(space=space, default=default, category=category, **kwargs)
|
||||
|
||||
def get_space(self, name: str) -> Integer:
|
||||
def get_space(self, name: str) -> 'Integer':
|
||||
"""
|
||||
Create skopt optimization space.
|
||||
:param name: A name of parameter field.
|
||||
@ -90,7 +92,7 @@ class FloatParameter(BaseParameter):
|
||||
raise OperationalException('IntParameter space must be [min, max]')
|
||||
super().__init__(space=space, default=default, category=category, **kwargs)
|
||||
|
||||
def get_space(self, name: str) -> Real:
|
||||
def get_space(self, name: str) -> 'Real':
|
||||
"""
|
||||
Create skopt optimization space.
|
||||
:param name: A name of parameter field.
|
||||
@ -121,7 +123,7 @@ class CategoricalParameter(BaseParameter):
|
||||
'IntParameter space must be [a, b, ...] (at least two parameters)')
|
||||
super().__init__(space=space, default=default, category=category, **kwargs)
|
||||
|
||||
def get_space(self, name: str) -> Categorical:
|
||||
def get_space(self, name: str) -> 'Categorical':
|
||||
"""
|
||||
Create skopt optimization space.
|
||||
:param name: A name of parameter field.
|
||||
|
Loading…
Reference in New Issue
Block a user