From 5c859d929b640523b73ffaf2691cf2562993e1c5 Mon Sep 17 00:00:00 2001 From: viotemp1 Date: Sun, 13 Apr 2025 11:06:39 +0300 Subject: [PATCH] add optunaspaces.py --- freqtrade/optimize/space/optunaspaces.py | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 freqtrade/optimize/space/optunaspaces.py diff --git a/freqtrade/optimize/space/optunaspaces.py b/freqtrade/optimize/space/optunaspaces.py new file mode 100644 index 000000000..d574afe0f --- /dev/null +++ b/freqtrade/optimize/space/optunaspaces.py @@ -0,0 +1,59 @@ +from collections.abc import Sequence +from typing import Any, Protocol + +from optuna.distributions import CategoricalDistribution, FloatDistribution, IntDistribution + + +class DimensionProtocol(Protocol): + name: str + + +class ft_CategoricalDistribution(CategoricalDistribution): + def __init__( + self, + categories: Sequence[Any], + name: str, + **kwargs, + ): + self.name = name + self.categories = categories + # if len(categories) <= 1: + # raise Exception(f"need at least 2 categories for {name}") + return super().__init__(categories) + + def __repr__(self): + return f"CategoricalDistribution({self.categories})" + + +class ft_IntDistribution(IntDistribution): + def __init__( + self, + low: int | float, + high: int | float, + name: str, + **kwargs, + ): + self.name = name + self.low = low + self.high = high + return super().__init__(int(low), int(high), **kwargs) + + def __repr__(self): + return f"IntDistribution(low={self.low}, high={self.high})" + + +class ft_FloatDistribution(FloatDistribution): + def __init__( + self, + low: float, + high: float, + name: str, + **kwargs, + ): + self.name = name + self.low = low + self.high = high + return super().__init__(low, high, **kwargs) + + def __repr__(self): + return f"FloatDistribution(low={self.low}, high={self.high}, step={self.step})"