fix KeyError: directional-mode diagnostics (no more entered/hedged/exit_type columns)
Browse files
train.py
CHANGED
|
@@ -229,30 +229,24 @@ def _build_training_dataset(
|
|
| 229 |
if len(df) == 0:
|
| 230 |
raise RuntimeError("No valid training rows produced")
|
| 231 |
df = df.sort_values("slug_ts").reset_index(drop=True)
|
| 232 |
-
#
|
|
|
|
| 233 |
if "realized_pnl" in df.columns:
|
| 234 |
-
import numpy as _np
|
| 235 |
pnls = df["realized_pnl"].to_numpy()
|
| 236 |
pcts = _np.percentile(pnls, [1, 5, 25, 50, 75, 95, 99])
|
| 237 |
-
log(f"[data] realized_pnl percentiles "
|
| 238 |
f"1%={pcts[0]:.2f} 5%={pcts[1]:.2f} 25%={pcts[2]:.2f} "
|
| 239 |
f"50%={pcts[3]:.2f} 75%={pcts[4]:.2f} 95%={pcts[5]:.2f} 99%={pcts[6]:.2f}")
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
f"
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
log(f"[data] policy fire rates: entered={entered_rate:.3f} "
|
| 251 |
-
f"hedged|entered={hedge_rate_given_entry:.3f}")
|
| 252 |
-
if "exit_type" in df.columns:
|
| 253 |
-
vc = df["exit_type"].value_counts(normalize=True).to_dict()
|
| 254 |
-
log(f"[data] exit_type breakdown: "
|
| 255 |
-
+ " ".join(f"{k}={v:.3f}" for k, v in vc.items()))
|
| 256 |
# re-sort eff_cache to mirror df row order (df was just sorted by slug_ts)
|
| 257 |
slug_to_idx = {c["slug"]: i for i, c in enumerate(eff_cache)}
|
| 258 |
reordered = [eff_cache[slug_to_idx[s]] for s in df["slug"].tolist() if s in slug_to_idx]
|
|
|
|
| 229 |
if len(df) == 0:
|
| 230 |
raise RuntimeError("No valid training rows produced")
|
| 231 |
df = df.sort_values("slug_ts").reset_index(drop=True)
|
| 232 |
+
# Directional-mode diagnostics
|
| 233 |
+
import numpy as _np
|
| 234 |
if "realized_pnl" in df.columns:
|
|
|
|
| 235 |
pnls = df["realized_pnl"].to_numpy()
|
| 236 |
pcts = _np.percentile(pnls, [1, 5, 25, 50, 75, 95, 99])
|
| 237 |
+
log(f"[data] realized_pnl(buy_up_@120) percentiles "
|
| 238 |
f"1%={pcts[0]:.2f} 5%={pcts[1]:.2f} 25%={pcts[2]:.2f} "
|
| 239 |
f"50%={pcts[3]:.2f} 75%={pcts[4]:.2f} 95%={pcts[5]:.2f} 99%={pcts[6]:.2f}")
|
| 240 |
+
if "up_ask_120" in df.columns:
|
| 241 |
+
ua = df["up_ask_120"].to_numpy()
|
| 242 |
+
da = df["dn_ask_120"].to_numpy()
|
| 243 |
+
log(f"[data] up_ask_120: median={_np.median(ua):.3f} "
|
| 244 |
+
f"5%={_np.quantile(ua, 0.05):.3f} 95%={_np.quantile(ua, 0.95):.3f} | "
|
| 245 |
+
f"dn_ask_120: median={_np.median(da):.3f}")
|
| 246 |
+
cheap_either = float(((ua <= 0.40) | (da <= 0.40)).mean())
|
| 247 |
+
cheap_both_lo = float(((ua <= 0.35) | (da <= 0.35)).mean())
|
| 248 |
+
log(f"[data] entry opportunity: "
|
| 249 |
+
f"some_side≤$0.40={cheap_either:.3f} some_side≤$0.35={cheap_both_lo:.3f}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
# re-sort eff_cache to mirror df row order (df was just sorted by slug_ts)
|
| 251 |
slug_to_idx = {c["slug"]: i for i, c in enumerate(eff_cache)}
|
| 252 |
reordered = [eff_cache[slug_to_idx[s]] for s in df["slug"].tolist() if s in slug_to_idx]
|