2022-05-03 08:14:17 +00:00
|
|
|
# pragma pylint: disable=attribute-defined-outside-init
|
|
|
|
|
|
|
|
"""
|
|
|
|
This module load a custom model for freqai
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
from pathlib import Path
|
|
|
|
|
2022-09-18 11:31:52 +00:00
|
|
|
from freqtrade.constants import USERPATH_FREQAIMODELS, Config
|
2022-05-03 08:14:17 +00:00
|
|
|
from freqtrade.exceptions import OperationalException
|
|
|
|
from freqtrade.freqai.freqai_interface import IFreqaiModel
|
|
|
|
from freqtrade.resolvers import IResolver
|
|
|
|
|
2022-05-04 15:42:34 +00:00
|
|
|
|
2022-05-03 08:14:17 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class FreqaiModelResolver(IResolver):
|
|
|
|
"""
|
|
|
|
This class contains all the logic to load custom hyperopt loss class
|
|
|
|
"""
|
2022-05-04 15:42:34 +00:00
|
|
|
|
2022-05-03 08:14:17 +00:00
|
|
|
object_type = IFreqaiModel
|
|
|
|
object_type_str = "FreqaiModel"
|
|
|
|
user_subdir = USERPATH_FREQAIMODELS
|
2022-07-12 16:09:17 +00:00
|
|
|
initial_search_path = (
|
|
|
|
Path(__file__).parent.parent.joinpath("freqai/prediction_models").resolve()
|
|
|
|
)
|
2022-10-14 17:49:06 +00:00
|
|
|
extra_path = "freqaimodel_path"
|
2022-05-03 08:14:17 +00:00
|
|
|
|
|
|
|
@staticmethod
|
2022-09-18 11:31:52 +00:00
|
|
|
def load_freqaimodel(config: Config) -> IFreqaiModel:
|
2022-05-03 08:14:17 +00:00
|
|
|
"""
|
|
|
|
Load the custom class from config parameter
|
|
|
|
:param config: configuration dictionary
|
|
|
|
"""
|
2022-07-12 16:09:17 +00:00
|
|
|
disallowed_models = ["BaseRegressionModel", "BaseTensorFlowModel"]
|
2022-05-03 08:14:17 +00:00
|
|
|
|
2022-05-04 15:42:34 +00:00
|
|
|
freqaimodel_name = config.get("freqaimodel")
|
2022-05-03 08:14:17 +00:00
|
|
|
if not freqaimodel_name:
|
|
|
|
raise OperationalException(
|
|
|
|
"No freqaimodel set. Please use `--freqaimodel` to "
|
|
|
|
"specify the FreqaiModel class to use.\n"
|
|
|
|
)
|
2022-07-12 16:09:17 +00:00
|
|
|
if freqaimodel_name in disallowed_models:
|
|
|
|
raise OperationalException(
|
2022-07-22 15:46:14 +00:00
|
|
|
f"{freqaimodel_name} is a baseclass and cannot be used directly. Please choose "
|
2022-07-12 16:09:17 +00:00
|
|
|
"an existing child class or inherit from this baseclass.\n"
|
|
|
|
)
|
2022-05-04 15:42:34 +00:00
|
|
|
freqaimodel = FreqaiModelResolver.load_object(
|
|
|
|
freqaimodel_name,
|
|
|
|
config,
|
|
|
|
kwargs={"config": config},
|
|
|
|
)
|
2022-05-03 08:14:17 +00:00
|
|
|
|
|
|
|
return freqaimodel
|