types: slightly improved typing
This commit is contained in:
@@ -9,7 +9,6 @@ from abc import ABC
|
|||||||
from typing import TypeAlias
|
from typing import TypeAlias
|
||||||
|
|
||||||
from sklearn.base import RegressorMixin
|
from sklearn.base import RegressorMixin
|
||||||
from skopt.space import Dimension # , Integer, Categorical,
|
|
||||||
|
|
||||||
from freqtrade.constants import Config
|
from freqtrade.constants import Config
|
||||||
from freqtrade.exchange import timeframe_to_minutes
|
from freqtrade.exchange import timeframe_to_minutes
|
||||||
@@ -17,6 +16,7 @@ from freqtrade.misc import round_dict
|
|||||||
from freqtrade.optimize.space import SKDecimal
|
from freqtrade.optimize.space import SKDecimal
|
||||||
from freqtrade.strategy import IStrategy
|
from freqtrade.strategy import IStrategy
|
||||||
from freqtrade.strategy.parameters import (
|
from freqtrade.strategy.parameters import (
|
||||||
|
DimensionProtocol,
|
||||||
ft_CategoricalDistribution,
|
ft_CategoricalDistribution,
|
||||||
ft_IntDistribution,
|
ft_IntDistribution,
|
||||||
)
|
)
|
||||||
@@ -45,7 +45,7 @@ class IHyperOpt(ABC):
|
|||||||
# Assign timeframe to be used in hyperopt
|
# Assign timeframe to be used in hyperopt
|
||||||
IHyperOpt.timeframe = str(config["timeframe"])
|
IHyperOpt.timeframe = str(config["timeframe"])
|
||||||
|
|
||||||
def generate_estimator(self, dimensions: list[Dimension], **kwargs) -> EstimatorType:
|
def generate_estimator(self, dimensions: list[DimensionProtocol], **kwargs) -> EstimatorType:
|
||||||
"""
|
"""
|
||||||
Return base_estimator.
|
Return base_estimator.
|
||||||
Can be any of "TPESampler", "GPSampler", "CmaEsSampler", "NSGAIISampler"
|
Can be any of "TPESampler", "GPSampler", "CmaEsSampler", "NSGAIISampler"
|
||||||
@@ -69,7 +69,7 @@ class IHyperOpt(ABC):
|
|||||||
|
|
||||||
return roi_table
|
return roi_table
|
||||||
|
|
||||||
def roi_space(self) -> list[Dimension]:
|
def roi_space(self) -> list[DimensionProtocol]:
|
||||||
"""
|
"""
|
||||||
Create a ROI space.
|
Create a ROI space.
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ class IHyperOpt(ABC):
|
|||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
def stoploss_space(self) -> list[Dimension]:
|
def stoploss_space(self) -> list[DimensionProtocol]:
|
||||||
"""
|
"""
|
||||||
Create a stoploss space.
|
Create a stoploss space.
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ class IHyperOpt(ABC):
|
|||||||
"trailing_only_offset_is_reached": params["trailing_only_offset_is_reached"],
|
"trailing_only_offset_is_reached": params["trailing_only_offset_is_reached"],
|
||||||
}
|
}
|
||||||
|
|
||||||
def trailing_space(self) -> list[Dimension]:
|
def trailing_space(self) -> list[DimensionProtocol]:
|
||||||
"""
|
"""
|
||||||
Create a trailing stoploss space.
|
Create a trailing stoploss space.
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ class IHyperOpt(ABC):
|
|||||||
ft_CategoricalDistribution("trailing_only_offset_is_reached", [True, False]),
|
ft_CategoricalDistribution("trailing_only_offset_is_reached", [True, False]),
|
||||||
]
|
]
|
||||||
|
|
||||||
def max_open_trades_space(self) -> list[Dimension]:
|
def max_open_trades_space(self) -> list[DimensionProtocol]:
|
||||||
"""
|
"""
|
||||||
Create a max open trades space.
|
Create a max open trades space.
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ from freqtrade.optimize.hyperopt_loss.hyperopt_loss_interface import IHyperOptLo
|
|||||||
from freqtrade.optimize.hyperopt_tools import HyperoptStateContainer, HyperoptTools
|
from freqtrade.optimize.hyperopt_tools import HyperoptStateContainer, HyperoptTools
|
||||||
from freqtrade.optimize.optimize_reports import generate_strategy_stats
|
from freqtrade.optimize.optimize_reports import generate_strategy_stats
|
||||||
from freqtrade.resolvers.hyperopt_resolver import HyperOptLossResolver
|
from freqtrade.resolvers.hyperopt_resolver import HyperOptLossResolver
|
||||||
|
from freqtrade.strategy.parameters import DimensionProtocol
|
||||||
from freqtrade.util.dry_run_wallet import get_dry_run_wallet
|
from freqtrade.util.dry_run_wallet import get_dry_run_wallet
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +41,6 @@ with warnings.catch_warnings():
|
|||||||
warnings.filterwarnings("ignore", category=FutureWarning)
|
warnings.filterwarnings("ignore", category=FutureWarning)
|
||||||
# warnings.filterwarnings("ignore", category=ExperimentalWarning)
|
# warnings.filterwarnings("ignore", category=ExperimentalWarning)
|
||||||
import optuna
|
import optuna
|
||||||
from skopt.space import Dimension
|
|
||||||
|
|
||||||
from freqtrade.optimize.space.decimalspace import SKDecimal
|
from freqtrade.optimize.space.decimalspace import SKDecimal
|
||||||
from freqtrade.strategy.parameters import (
|
from freqtrade.strategy.parameters import (
|
||||||
@@ -71,14 +71,14 @@ class HyperOptimizer:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, config: Config) -> None:
|
def __init__(self, config: Config) -> None:
|
||||||
self.buy_space: list[Dimension] = []
|
self.buy_space: list[DimensionProtocol] = []
|
||||||
self.sell_space: list[Dimension] = []
|
self.sell_space: list[DimensionProtocol] = []
|
||||||
self.protection_space: list[Dimension] = []
|
self.protection_space: list[DimensionProtocol] = []
|
||||||
self.roi_space: list[Dimension] = []
|
self.roi_space: list[DimensionProtocol] = []
|
||||||
self.stoploss_space: list[Dimension] = []
|
self.stoploss_space: list[DimensionProtocol] = []
|
||||||
self.trailing_space: list[Dimension] = []
|
self.trailing_space: list[DimensionProtocol] = []
|
||||||
self.max_open_trades_space: list[Dimension] = []
|
self.max_open_trades_space: list[DimensionProtocol] = []
|
||||||
self.dimensions: list[Dimension] = []
|
self.dimensions: list[DimensionProtocol] = []
|
||||||
self.o_dimensions: dict = {}
|
self.o_dimensions: dict = {}
|
||||||
|
|
||||||
self.config = config
|
self.config = config
|
||||||
@@ -146,7 +146,7 @@ class HyperOptimizer:
|
|||||||
|
|
||||||
def _get_params_dict(
|
def _get_params_dict(
|
||||||
self,
|
self,
|
||||||
dimensions: list[Dimension],
|
dimensions: list[DimensionProtocol],
|
||||||
raw_params: dict[str, Any],
|
raw_params: dict[str, Any],
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
# logger.info(f"_get_params_dict: {raw_params}")
|
# logger.info(f"_get_params_dict: {raw_params}")
|
||||||
@@ -404,7 +404,7 @@ class HyperOptimizer:
|
|||||||
"total_profit": total_profit,
|
"total_profit": total_profit,
|
||||||
}
|
}
|
||||||
|
|
||||||
def convert_dimensions_to_optuna_space(self, s_dimensions: list[Dimension]) -> dict:
|
def convert_dimensions_to_optuna_space(self, s_dimensions: list[DimensionProtocol]) -> dict:
|
||||||
o_dimensions: dict[str, optuna.distributions.BaseDistribution] = {}
|
o_dimensions: dict[str, optuna.distributions.BaseDistribution] = {}
|
||||||
for original_dim in s_dimensions:
|
for original_dim in s_dimensions:
|
||||||
if isinstance(original_dim, SKDecimal):
|
if isinstance(original_dim, SKDecimal):
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import logging
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from typing import Any, Union
|
from typing import Any, Protocol, Union
|
||||||
|
|
||||||
from freqtrade.enums import HyperoptState
|
from freqtrade.enums import HyperoptState
|
||||||
from freqtrade.optimize.hyperopt_tools import HyperoptStateContainer
|
from freqtrade.optimize.hyperopt_tools import HyperoptStateContainer
|
||||||
@@ -24,6 +24,10 @@ from freqtrade.exceptions import OperationalException
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class DimensionProtocol(Protocol):
|
||||||
|
name: str
|
||||||
|
|
||||||
|
|
||||||
class ft_CategoricalDistribution(CategoricalDistribution):
|
class ft_CategoricalDistribution(CategoricalDistribution):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
Reference in New Issue
Block a user