commanderzee commited on
Commit
4974ef9
·
verified ·
1 Parent(s): 1321f62

fix KeyError: directional-mode diagnostics (no more entered/hedged/exit_type columns)

Browse files
Files changed (1) hide show
  1. train.py +13 -19
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
- # Policy-simulation diagnostics (the "real" picture)
 
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
- log(f"[data] realized pnl buckets: "
241
- f">$20={float((pnls>20).mean()):.3f} "
242
- f">$0={float((pnls>0).mean()):.3f} "
243
- f"=0(never_entered)={float((pnls==0).mean()):.3f} "
244
- f"<0={float((pnls<0).mean()):.3f}")
245
- entered_rate = float(df["entered"].mean())
246
- if df["entered"].sum() > 0:
247
- hedge_rate_given_entry = float(df.loc[df["entered"] == 1, "hedged"].mean())
248
- else:
249
- hedge_rate_given_entry = 0.0
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]