change SKDecimal low/high to be rounded by decimals
This commit is contained in:
@@ -330,7 +330,6 @@ class Hyperopt:
|
|||||||
self.config,
|
self.config,
|
||||||
self.hyperopter.get_strategy_name(),
|
self.hyperopter.get_strategy_name(),
|
||||||
self.current_best_epoch,
|
self.current_best_epoch,
|
||||||
self.hyperopter.o_dimensions,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
HyperoptTools.show_epoch_details(
|
HyperoptTools.show_epoch_details(
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ from typing import Any
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import rapidjson
|
import rapidjson
|
||||||
from optuna.distributions import BaseDistribution
|
|
||||||
from pandas import isna, json_normalize
|
from pandas import isna, json_normalize
|
||||||
|
|
||||||
from freqtrade.constants import FTHYPT_FILEVERSION, Config
|
from freqtrade.constants import FTHYPT_FILEVERSION, Config
|
||||||
@@ -15,7 +14,6 @@ from freqtrade.enums import HyperoptState
|
|||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.misc import deep_merge_dicts, round_dict, safe_value_fallback2
|
from freqtrade.misc import deep_merge_dicts, round_dict, safe_value_fallback2
|
||||||
from freqtrade.optimize.hyperopt_epoch_filters import hyperopt_filter_epochs
|
from freqtrade.optimize.hyperopt_epoch_filters import hyperopt_filter_epochs
|
||||||
from freqtrade.optimize.space import SKDecimal, _adjust_discrete_uniform
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -67,22 +65,11 @@ class HyperoptTools:
|
|||||||
params,
|
params,
|
||||||
strategy_name: str,
|
strategy_name: str,
|
||||||
filename: Path,
|
filename: Path,
|
||||||
o_dimensions: dict[str, BaseDistribution] | None = None,
|
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Generate files
|
Generate files
|
||||||
"""
|
"""
|
||||||
final_params = deepcopy(params["params_not_optimized"])
|
final_params = deepcopy(params["params_not_optimized"])
|
||||||
if o_dimensions:
|
|
||||||
for key, val in params["params_details"].items():
|
|
||||||
if isinstance(val, dict):
|
|
||||||
for key1, val1 in val.items():
|
|
||||||
if isinstance(o_dimensions.get(key1), SKDecimal):
|
|
||||||
step = getattr(o_dimensions.get(key1), "step", None)
|
|
||||||
if step:
|
|
||||||
params["params_details"][key][key1] = _adjust_discrete_uniform(
|
|
||||||
val1, step
|
|
||||||
)
|
|
||||||
final_params = deep_merge_dicts(params["params_details"], final_params)
|
final_params = deep_merge_dicts(params["params_details"], final_params)
|
||||||
final_params = {
|
final_params = {
|
||||||
"strategy_name": strategy_name,
|
"strategy_name": strategy_name,
|
||||||
@@ -115,15 +102,12 @@ class HyperoptTools:
|
|||||||
config: Config,
|
config: Config,
|
||||||
strategy_name: str,
|
strategy_name: str,
|
||||||
params: dict,
|
params: dict,
|
||||||
o_dimensions: dict[str, BaseDistribution] | None = None,
|
|
||||||
):
|
):
|
||||||
if params.get(FTHYPT_FILEVERSION, 1) >= 2 and not config.get("disableparamexport", False):
|
if params.get(FTHYPT_FILEVERSION, 1) >= 2 and not config.get("disableparamexport", False):
|
||||||
# Export parameters ...
|
# Export parameters ...
|
||||||
fn = HyperoptTools.get_strategy_filename(config, strategy_name)
|
fn = HyperoptTools.get_strategy_filename(config, strategy_name)
|
||||||
if fn:
|
if fn:
|
||||||
HyperoptTools.export_params(
|
HyperoptTools.export_params(params, strategy_name, fn.with_suffix(".json"))
|
||||||
params, strategy_name, fn.with_suffix(".json"), o_dimensions
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
logger.warning("Strategy not found, not exporting parameter file.")
|
logger.warning("Strategy not found, not exporting parameter file.")
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from .decimalspace import SKDecimal, _adjust_discrete_uniform
|
from .decimalspace import SKDecimal
|
||||||
from .optunaspaces import (
|
from .optunaspaces import (
|
||||||
DimensionProtocol,
|
DimensionProtocol,
|
||||||
ft_CategoricalDistribution,
|
ft_CategoricalDistribution,
|
||||||
@@ -13,4 +13,4 @@ Categorical = ft_CategoricalDistribution
|
|||||||
Integer = ft_IntDistribution
|
Integer = ft_IntDistribution
|
||||||
Real = ft_FloatDistribution
|
Real = ft_FloatDistribution
|
||||||
|
|
||||||
__all__ = ["Categorical", "Dimension", "Integer", "Real", "SKDecimal", "_adjust_discrete_uniform"]
|
__all__ = ["Categorical", "Dimension", "Integer", "Real", "SKDecimal"]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import decimal
|
from math import log10
|
||||||
|
|
||||||
from optuna.distributions import FloatDistribution
|
from optuna.distributions import FloatDistribution
|
||||||
|
|
||||||
@@ -22,32 +22,7 @@ class SKDecimal(FloatDistribution):
|
|||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
low=_adjust_discrete_uniform(low, self.step),
|
low=round(low, int(log10(1 / self.step))) if self.step < 1 else low,
|
||||||
high=_adjust_discrete_uniform_high(low, high, self.step),
|
high=round(high, int(log10(1 / self.step))) if self.step < 1 else high,
|
||||||
step=self.step,
|
step=self.step,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _adjust_discrete_uniform_high(low: float, high: float, step: float | None) -> float:
|
|
||||||
if step:
|
|
||||||
d_high = decimal.Decimal(str(high))
|
|
||||||
d_low = decimal.Decimal(str(low))
|
|
||||||
d_step = decimal.Decimal(str(step))
|
|
||||||
|
|
||||||
d_r = d_high - d_low
|
|
||||||
|
|
||||||
if d_r % d_step != decimal.Decimal("0"):
|
|
||||||
high = float((d_r // d_step) * d_step + d_low)
|
|
||||||
|
|
||||||
return high
|
|
||||||
|
|
||||||
|
|
||||||
def _adjust_discrete_uniform(val: float, step: float | None) -> float:
|
|
||||||
if step:
|
|
||||||
d_val = decimal.Decimal(str(val))
|
|
||||||
d_step = decimal.Decimal(str(step))
|
|
||||||
|
|
||||||
if d_val % d_step != decimal.Decimal("0"):
|
|
||||||
val = float((d_val // d_step) * d_step)
|
|
||||||
|
|
||||||
return val
|
|
||||||
|
|||||||
Reference in New Issue
Block a user