From 1c6f96657974f69fbf97ea135740f180393d0239 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 19 Aug 2022 15:03:03 +0200 Subject: [PATCH] Hyperopt: simplify parameter "can_optimize" handling --- freqtrade/strategy/parameters.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/freqtrade/strategy/parameters.py b/freqtrade/strategy/parameters.py index 83dd41de9..e64a1e4c0 100644 --- a/freqtrade/strategy/parameters.py +++ b/freqtrade/strategy/parameters.py @@ -57,6 +57,12 @@ class BaseParameter(ABC): Get-space - will be used by Hyperopt to get the hyperopt Space """ + def can_optimize(self): + return ( + self.in_space + and self.optimize + ) + class NumericParameter(BaseParameter): """ Internal parameter used for Numeric purposes """ @@ -133,7 +139,7 @@ class IntParameter(NumericParameter): Returns a List with 1 item (`value`) in "non-hyperopt" mode, to avoid calculating 100ds of indicators. """ - if self.in_space and self.optimize: + if self.can_optimize(): # Scikit-optimize ranges are "inclusive", while python's "range" is exclusive return range(self.low, self.high + 1) else: @@ -212,7 +218,7 @@ class DecimalParameter(NumericParameter): Returns a List with 1 item (`value`) in "non-hyperopt" mode, to avoid calculating 100ds of indicators. """ - if self.in_space and self.optimize: + if self.can_optimize(): low = int(self.low * pow(10, self._decimals)) high = int(self.high * pow(10, self._decimals)) + 1 return [round(n * pow(0.1, self._decimals), self._decimals) for n in range(low, high)] @@ -261,7 +267,7 @@ class CategoricalParameter(BaseParameter): Returns a List with 1 item (`value`) in "non-hyperopt" mode, to avoid calculating 100ds of indicators. """ - if self.in_space and self.optimize: + if self.can_optimize(): return self.opt_range else: return [self.value]