"""Minimal Python example: realized measures and a GARCH fit with backend="auto|cpu|metal" and explicit CPU fallback.""" import sys import numpy as np import raid backend = sys.argv[1] if len(sys.argv) > 1 else "auto" print("devices:", [d["name"] for d in raid.devices()]) rng = np.random.default_rng(20261102) sessions, M = 100, 390 r = rng.normal(0, 1e-3, size=sessions * M); offsets = np.arange(0, sessions * M + 1, M) m = raid.realized_measures(r, offsets, backend=backend) # falls back to CPU when Metal is unavailable print(f"backend={m['backend']} precision={m['precision']} wall={m['wall_seconds']*1e3:.2f} ms RV[0]={m['rv'][0]:.3e}") daily = m["ret"] # daily open-to-close returns g = raid.garch_fit(np.concatenate([daily, rng.normal(0, 0.01, 400)]), model="gjr", dist="student_t", horizon=5) print("GJR-t:", dict(zip(g["names"], np.round(g["coefficients"], 5))), "converged:", g["ok"])