Repository Public Research preview
1"""Daily variance proxies (percent^2) assembled from the panel columns (decision D-04).23primary 'rv5ss_on' : rv_5m_ss + r_on^2 (subsampled 5-min RV over the session + squared overnight return; equals rv_5m_ss4 for futures/FX/crypto where r_on is the break return or zero)5secondary 'rv5_on' : rv_5m + r_on^26 'rv1_on' : rv_1m + r_on^27 'bv5_on' : bv_5m + r_on^2 (jump-robust)8 'medrv_on' : medrv_5m + r_on^29 'r2' : r^2 (squared daily close-to-close return; noisy diagnostic)10 'rv5ss_scaled': rv_5m_ss * c with c = mean(r^2)/mean(rv_5m_ss) over the ESTIMATION window at the origin11 (Hansen & Lunde 2005 whole-day scaling, computed without look-ahead by the driver)12Negative/zero values are invalid; the driver sets loss = NaN where the proxy is invalid (valid_rm False)."""13from __future__ import annotations1415import numpy as np16import pandas as pd1718PROXIES = ["rv5ss_on", "rv5_on", "rv1_on", "bv5_on", "medrv_on", "r2", "rv5ss_scaled"]192021def proxy_series(panel: pd.DataFrame, name: str) -> np.ndarray:22 on2 = panel["r_on"].fillna(0.0).values ** 223 if name == "rv5ss_on":24 v = panel["rv_5m_ss"].values + on225 elif name == "rv5_on":26 v = panel["rv_5m"].values + on227 elif name == "rv1_on":28 v = panel["rv_1m"].values + on229 elif name == "bv5_on":30 v = panel["bv_5m"].values + on231 elif name == "medrv_on":32 v = panel["medrv_5m"].values + on233 elif name == "r2":34 v = panel["r"].values ** 235 elif name == "rv5ss_scaled":36 v = panel["rv_5m_ss"].values.copy() # scaling applied by the driver37 else:38 raise KeyError(name)39 v = np.asarray(v, float)40 if name != "r2":41 v = np.where(panel["valid_rm"].values, v, np.nan)42 return v43