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