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

[auto] Sync code from GitHub

Browse files
Files changed (1) hide show
  1. evaluate.py +45 -0
evaluate.py CHANGED
@@ -432,6 +432,51 @@ def run_evaluation(tsl_pct=config.DEFAULT_TSL_PCT,
432
  with open("evaluation_results.json","w") as f:
433
  json.dump(results, f, indent=2, default=str)
434
  print(f"\n Saved β†’ evaluation_results.json")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
435
  return results
436
 
437
 
 
432
  with open("evaluation_results.json","w") as f:
433
  json.dump(results, f, indent=2, default=str)
434
  print(f"\n Saved β†’ evaluation_results.json")
435
+
436
+ # ── Write date-stamped sweep cache if this is a sweep year ────────────────
437
+ SWEEP_YEARS = [2008, 2013, 2015, 2017, 2019, 2021]
438
+ start_yr = results.get("start_year") or (
439
+ results.get(winner, {}).get("start_year") if winner else None)
440
+ # Read from training_summary.json
441
+ if start_yr is None:
442
+ try:
443
+ import os as _os
444
+ summ_path = _os.path.join(config.MODELS_DIR, "training_summary.json")
445
+ if _os.path.exists(summ_path):
446
+ with open(summ_path) as _f:
447
+ start_yr = json.load(_f).get("start_year")
448
+ except Exception:
449
+ pass
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