File size: 1,485 Bytes
590a501 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | """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 <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
|