Spaces:
Running
Running
[auto] Sync code from GitHub
Browse files- 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
|
| 454 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
_z = 0.0
|
| 456 |
try:
|
| 457 |
-
if
|
| 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":
|
| 466 |
-
"ann_return":
|
| 467 |
-
"z_score":
|
| 468 |
-
"sharpe":
|
| 469 |
-
"max_dd":
|
| 470 |
"winner_model": winner,
|
| 471 |
-
"start_year":
|
| 472 |
-
"sweep_date":
|
| 473 |
}
|
| 474 |
-
|
| 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 |
|