2018-11-24 19:14:08 +00:00
|
|
|
# pragma pylint: disable=attribute-defined-outside-init
|
|
|
|
|
|
|
|
"""
|
2019-11-13 08:38:06 +00:00
|
|
|
This module load custom hyperopt
|
2018-11-24 19:14:08 +00:00
|
|
|
"""
|
2024-05-12 14:21:12 +00:00
|
|
|
|
2018-11-24 19:14:08 +00:00
|
|
|
import logging
|
2018-11-24 19:39:16 +00:00
|
|
|
from pathlib import Path
|
2018-11-24 19:14:08 +00:00
|
|
|
|
2022-09-18 11:31:52 +00:00
|
|
|
from freqtrade.constants import HYPEROPT_LOSS_BUILTIN, USERPATH_HYPEROPTS, Config
|
2019-12-30 14:02:17 +00:00
|
|
|
from freqtrade.exceptions import OperationalException
|
2024-11-10 13:39:42 +00:00
|
|
|
from freqtrade.optimize.hyperopt_loss.hyperopt_loss_interface import IHyperOptLoss
|
2018-11-24 19:14:08 +00:00
|
|
|
from freqtrade.resolvers import IResolver
|
|
|
|
|
2020-09-28 17:39:41 +00:00
|
|
|
|
2018-11-24 19:14:08 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-07-16 04:27:23 +00:00
|
|
|
class HyperOptLossResolver(IResolver):
|
|
|
|
"""
|
|
|
|
This class contains all the logic to load custom hyperopt loss class
|
|
|
|
"""
|
2024-05-12 14:21:12 +00:00
|
|
|
|
2019-12-24 12:34:37 +00:00
|
|
|
object_type = IHyperOptLoss
|
2019-12-24 12:54:46 +00:00
|
|
|
object_type_str = "HyperoptLoss"
|
|
|
|
user_subdir = USERPATH_HYPEROPTS
|
2024-05-12 14:21:12 +00:00
|
|
|
initial_search_path = Path(__file__).parent.parent.joinpath("optimize/hyperopt_loss").resolve()
|
2019-07-16 04:27:23 +00:00
|
|
|
|
2019-12-23 09:09:08 +00:00
|
|
|
@staticmethod
|
2022-09-18 11:31:52 +00:00
|
|
|
def load_hyperoptloss(config: Config) -> IHyperOptLoss:
|
2019-07-16 04:27:23 +00:00
|
|
|
"""
|
|
|
|
Load the custom class from config parameter
|
2019-10-13 00:41:25 +00:00
|
|
|
:param config: configuration dictionary
|
2019-07-16 04:27:23 +00:00
|
|
|
"""
|
|
|
|
|
2024-05-12 14:21:12 +00:00
|
|
|
hyperoptloss_name = config.get("hyperopt_loss")
|
2020-10-05 17:27:28 +00:00
|
|
|
if not hyperoptloss_name:
|
2020-10-28 06:58:55 +00:00
|
|
|
raise OperationalException(
|
|
|
|
"No Hyperopt loss set. Please use `--hyperopt-loss` to "
|
|
|
|
"specify the Hyperopt-Loss class to use.\n"
|
|
|
|
f"Built-in Hyperopt-loss-functions are: {', '.join(HYPEROPT_LOSS_BUILTIN)}"
|
|
|
|
)
|
2024-05-12 14:21:12 +00:00
|
|
|
hyperoptloss = HyperOptLossResolver.load_object(
|
|
|
|
hyperoptloss_name, config, kwargs={}, extra_dir=config.get("hyperopt_path")
|
|
|
|
)
|
2019-07-16 04:27:23 +00:00
|
|
|
|
2020-06-01 18:49:40 +00:00
|
|
|
# Assign timeframe to be used in hyperopt
|
2024-05-12 14:21:12 +00:00
|
|
|
hyperoptloss.__class__.timeframe = str(config["timeframe"])
|
2019-07-16 04:27:23 +00:00
|
|
|
|
2019-12-23 09:09:08 +00:00
|
|
|
return hyperoptloss
|