from __future__ import annotations from abc import ABC, abstractmethod from typing import Any, Dict, cast from pt_strategy.prediction import Prediction class PairsTradingModel(ABC): @abstractmethod def predict(self, pair: TradingPair) -> Prediction: # type: ignore[assignment] ... @staticmethod def create(config: Dict[str, Any]) -> PairsTradingModel: import importlib model_class_name = config.get("model_class", None) assert model_class_name is not None module_name, class_name = model_class_name.rsplit(".", 1) module = importlib.import_module(module_name) model_object = getattr(module, class_name)() return cast(PairsTradingModel, model_object)