1"""Conservative economic evaluation of the H5 exploratory hypothesis: a signal from the predictive median at horizon H2traded only when |median| exceeds k times the assumed round-trip cost; execution at the next bar's open with a3one-minute delay, cost = half-spread + fees + slippage in basis points. No quotes are available: the spread is an4assumption, reported as a sensitivity. Results are gross/net mean return per trade and a t-statistic with5day-clustered standard errors — never a profitability claim."""6from __future__ import annotations78import numpy as np9import pandas as pd1011from .statistics import cluster_bootstrap_mean121314def signal_pnl(median: np.ndarray, realised: np.ndarray, meta: pd.DataFrame, cost_bps: float = 5.0, k: float = 1.0) -> dict:15 cost = cost_bps / 1e416 sig = np.sign(median) * (np.abs(median) > k * cost)17 traded = sig != 018 gross = sig * realised19 net = gross - traded * cost20 out = {"cost_bps": cost_bps, "k": k, "n": int(len(sig)), "n_traded": int(traded.sum()), "share_traded": float(traded.mean())}21 if traded.sum() > 20:22 cl = pd.factorize(meta["session_date"])[0]23 g = cluster_bootstrap_mean(gross[traded], cl[traded], n_boot=500); n = cluster_bootstrap_mean(net[traded], cl[traded], n_boot=500)24 out.update({"gross_bps": g["mean"] * 1e4, "gross_lo": g["lo"] * 1e4, "gross_hi": g["hi"] * 1e4,25 "net_bps": n["mean"] * 1e4, "net_lo": n["lo"] * 1e4, "net_hi": n["hi"] * 1e4,26 "hit_rate": float((gross[traded] > 0).mean())})27 return out28