P2SAMAPA commited on
Commit
d21da44
·
verified ·
1 Parent(s): 3eee06d

[auto] Sync code from GitHub

Browse files
Files changed (1) hide show
  1. evaluate.py +26 -14
evaluate.py CHANGED
@@ -450,33 +450,45 @@ def run_evaluation(tsl_pct=config.DEFAULT_TSL_PCT,
450
  if start_yr in SWEEP_YEARS and winner and winner in results:
451
  from datetime import datetime as _dt, timezone as _tz, timedelta as _td
452
  _date_tag = (_dt.now(_tz.utc) - _td(hours=5)).strftime("%Y%m%d")
453
- w_metrics = results[winner].get("metrics", {})
454
- # Get z_score from latest_prediction.json if available
 
 
 
 
 
 
 
 
 
 
 
 
455
  _z = 0.0
456
  try:
457
- if _os.path.exists("latest_prediction.json"):
458
  with open("latest_prediction.json") as _pf:
459
  _pred = json.load(_pf)
460
  _preds = _pred.get("predictions", {})
461
- _z = _preds.get(winner, {}).get("z_score", 0.0)
462
  except Exception:
463
  pass
 
464
  sweep_payload = {
465
- "signal": results[winner].get("next_signal", "?"),
466
- "ann_return": round(float(w_metrics.get("ann_return", 0)) / 100, 6),
467
- "z_score": round(float(_z), 4),
468
- "sharpe": round(float(w_metrics.get("sharpe", 0)), 4),
469
- "max_dd": round(float(w_metrics.get("max_drawdown", 0)) / 100, 6),
470
  "winner_model": winner,
471
- "start_year": start_yr,
472
- "sweep_date": _date_tag,
473
  }
474
- import os as _os2
475
- _os2.makedirs("sweep", exist_ok=True)
476
  _sweep_fname = f"sweep/sweep_{start_yr}_{_date_tag}.json"
477
  with open(_sweep_fname, "w") as _sf:
478
  json.dump(sweep_payload, _sf, indent=2)
479
- print(f" Sweep cache saved → {_sweep_fname}")
480
  return results
481
 
482
 
 
450
  if start_yr in SWEEP_YEARS and winner and winner in results:
451
  from datetime import datetime as _dt, timezone as _tz, timedelta as _td
452
  _date_tag = (_dt.now(_tz.utc) - _td(hours=5)).strftime("%Y%m%d")
453
+ w_metrics = results[winner].get("metrics", {})
454
+
455
+ # Derive next signal from last row of audit_tail or all_signals
456
+ _next_signal = "?"
457
+ try:
458
+ _audit = results[winner].get("audit_tail") or results[winner].get("all_signals", [])
459
+ if _audit:
460
+ _last = _audit[-1]
461
+ _next_signal = _last.get("Signal_TSL") or _last.get("Signal") or "?"
462
+ except Exception:
463
+ pass
464
+
465
+ # Z-score from latest_prediction.json (written by predict.py before evaluate in workflow)
466
+ # Fall back to 0 if not available
467
  _z = 0.0
468
  try:
469
+ if os.path.exists("latest_prediction.json"):
470
  with open("latest_prediction.json") as _pf:
471
  _pred = json.load(_pf)
472
  _preds = _pred.get("predictions", {})
473
+ _z = float(_preds.get(winner, {}).get("z_score", 0.0) or 0.0)
474
  except Exception:
475
  pass
476
+
477
  sweep_payload = {
478
+ "signal": _next_signal,
479
+ "ann_return": round(float(w_metrics.get("ann_return", 0)) / 100, 6),
480
+ "z_score": round(_z, 4),
481
+ "sharpe": round(float(w_metrics.get("sharpe", 0)), 4),
482
+ "max_dd": round(float(w_metrics.get("max_drawdown", 0)) / 100, 6),
483
  "winner_model": winner,
484
+ "start_year": start_yr,
485
+ "sweep_date": _date_tag,
486
  }
487
+ os.makedirs("sweep", exist_ok=True)
 
488
  _sweep_fname = f"sweep/sweep_{start_yr}_{_date_tag}.json"
489
  with open(_sweep_fname, "w") as _sf:
490
  json.dump(sweep_payload, _sf, indent=2)
491
+ print(f" Sweep cache saved → {_sweep_fname} signal={_next_signal} z={_z:.3f}")
492
  return results
493
 
494