"""Qlib DataHandler for GP-mined factors (loaded from exported pickle).""" from __future__ import annotations import pickle from pathlib import Path from qlib.data.dataset.handler import DataHandlerLP class GPFactorHandler(DataHandlerLP): """ Load a pre-built GP factor handler from pickle. Used by qrun workflow YAML via module_path. """ def __init__( self, handler_path: str, instruments="csi300", start_time=None, end_time=None, fit_start_time=None, fit_end_time=None, **kwargs, ): path = Path(handler_path) if not path.is_absolute(): from config.settings import PROJECT_ROOT path = PROJECT_ROOT / path if not path.exists(): raise FileNotFoundError( f"GP handler pickle not found: {path}. " "Run: python scripts/build_gp_dataset.py --run-id " ) with path.open("rb") as f: loaded: DataHandlerLP = pickle.load(f) self.__dict__.update(loaded.__dict__) if start_time is not None: self.start_time = start_time if end_time is not None: self.end_time = end_time if fit_start_time is not None: self.fit_start_time = fit_start_time if fit_end_time is not None: self.fit_end_time = fit_end_time if instruments is not None: self.instruments = instruments