mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-11-29 00:23:07 +00:00
refactor: align wording from category to space
This commit is contained in:
@@ -41,16 +41,14 @@ class HyperStrategyMixin:
|
|||||||
self._ft_params_from_file = params
|
self._ft_params_from_file = params
|
||||||
# Init/loading of parameters is done as part of ft_bot_start().
|
# Init/loading of parameters is done as part of ft_bot_start().
|
||||||
|
|
||||||
def enumerate_parameters(
|
def enumerate_parameters(self, space: str | None = None) -> Iterator[tuple[str, BaseParameter]]:
|
||||||
self, category: str | None = None
|
|
||||||
) -> Iterator[tuple[str, BaseParameter]]:
|
|
||||||
"""
|
"""
|
||||||
Find all optimizable parameters and return (name, attr) iterator.
|
Find all optimizable parameters and return (name, attr) iterator.
|
||||||
:param category:
|
:param space: parameter space to filter for, or None for all spaces.
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
for category in [c for c in self._ft_hyper_params if category is None or c == category]:
|
for space in [c for c in self._ft_hyper_params if space is None or c == space]:
|
||||||
for par in self._ft_hyper_params[category].values():
|
for par in self._ft_hyper_params[space].values():
|
||||||
yield par.name, par
|
yield par.name, par
|
||||||
|
|
||||||
def ft_load_params_from_file(self) -> None:
|
def ft_load_params_from_file(self) -> None:
|
||||||
@@ -132,8 +130,8 @@ class HyperStrategyMixin:
|
|||||||
|
|
||||||
for param_name, param in params.items():
|
for param_name, param in params.items():
|
||||||
param.in_space = hyperopt and HyperoptTools.has_space(self.config, space)
|
param.in_space = hyperopt and HyperoptTools.has_space(self.config, space)
|
||||||
if not param.category:
|
if not param.space:
|
||||||
param.category = space
|
param.space = space
|
||||||
|
|
||||||
if param_values and param_name in param_values:
|
if param_values and param_name in param_values:
|
||||||
if param.load:
|
if param.load:
|
||||||
@@ -153,8 +151,8 @@ class HyperStrategyMixin:
|
|||||||
"""
|
"""
|
||||||
params: dict[str, dict] = defaultdict(dict)
|
params: dict[str, dict] = defaultdict(dict)
|
||||||
for name, p in self.enumerate_parameters():
|
for name, p in self.enumerate_parameters():
|
||||||
if p.category and (not p.optimize or not p.in_space):
|
if p.space and (not p.optimize or not p.in_space):
|
||||||
params[p.category][name] = p.value
|
params[p.space][name] = p.value
|
||||||
return params
|
return params
|
||||||
|
|
||||||
|
|
||||||
@@ -174,19 +172,19 @@ def detect_all_parameters(
|
|||||||
attr = getattr(obj, attr_name)
|
attr = getattr(obj, attr_name)
|
||||||
if not issubclass(attr.__class__, BaseParameter):
|
if not issubclass(attr.__class__, BaseParameter):
|
||||||
continue
|
continue
|
||||||
if not attr.category:
|
if not attr.space:
|
||||||
# Category auto detection
|
# space auto detection
|
||||||
for category in auto_categories:
|
for space in auto_categories:
|
||||||
if attr_name.startswith(category + "_"):
|
if attr_name.startswith(space + "_"):
|
||||||
attr.category = category
|
attr.space = space
|
||||||
break
|
break
|
||||||
if attr.category is None:
|
if attr.space is None:
|
||||||
raise OperationalException(f"Cannot determine parameter space for {attr_name}.")
|
raise OperationalException(f"Cannot determine parameter space for {attr_name}.")
|
||||||
|
|
||||||
if attr.category in ("all", "default") or attr.category.isidentifier() is False:
|
if attr.space in ("all", "default") or attr.space.isidentifier() is False:
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
f"'{attr.category}' is not a valid space. Parameter: {attr_name}."
|
f"'{attr.space}' is not a valid space. Parameter: {attr_name}."
|
||||||
)
|
)
|
||||||
attr.name = attr_name
|
attr.name = attr_name
|
||||||
result[attr.category][attr_name] = attr
|
result[attr.space][attr_name] = attr
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class BaseParameter(ABC):
|
|||||||
Defines a parameter that can be optimized by hyperopt.
|
Defines a parameter that can be optimized by hyperopt.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
category: str | None
|
space: str | None
|
||||||
default: Any
|
default: Any
|
||||||
value: Any
|
value: Any
|
||||||
in_space: bool = False
|
in_space: bool = False
|
||||||
@@ -61,7 +61,7 @@ class BaseParameter(ABC):
|
|||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
"Name is determined by parameter field name and can not be specified manually."
|
"Name is determined by parameter field name and can not be specified manually."
|
||||||
)
|
)
|
||||||
self.category = space
|
self.space = space
|
||||||
self._space_params = kwargs
|
self._space_params = kwargs
|
||||||
self.value = default
|
self.value = default
|
||||||
self.optimize = optimize
|
self.optimize = optimize
|
||||||
|
|||||||
Reference in New Issue
Block a user