fix: address pre-push review findings
This commit is contained in:
+10
-3
@@ -24,6 +24,7 @@ ML_WEIGHTS_PATH = os.path.join(BASE_DIR, "config", "ml_weights.json")
|
||||
|
||||
_BACKTEST_CACHE = {}
|
||||
_BACKTEST_CACHE_LOCK = threading.Lock()
|
||||
_BACKTEST_CACHE_LIMIT = 4
|
||||
|
||||
# Score brackets matching the dashboard assessment levels
|
||||
BRACKETS = SCORE_BRACKETS
|
||||
@@ -422,7 +423,12 @@ def clear_backtest_cache():
|
||||
|
||||
def _add_return_statistics(stats, period, returns):
|
||||
"""Add return summaries and a moving-block-bootstrap mean interval."""
|
||||
summary = summarize_returns(returns, block_size=min(30, len(returns)), n_resamples=400)
|
||||
horizon_days = int(period.removesuffix("d"))
|
||||
summary = summarize_returns(
|
||||
returns,
|
||||
block_size=min(horizon_days, len(returns)),
|
||||
n_resamples=400,
|
||||
)
|
||||
stats[f"avg_{period}"] = summary["mean"]
|
||||
stats[f"median_{period}"] = summary["median"]
|
||||
stats[f"win_rate_{period}"] = summary["win_rate"]
|
||||
@@ -449,8 +455,9 @@ def run_backtest(ml_mode=False):
|
||||
|
||||
result = _compute_backtest(ml_mode=ml_mode)
|
||||
with _BACKTEST_CACHE_LOCK:
|
||||
_BACKTEST_CACHE.clear()
|
||||
_BACKTEST_CACHE[signature] = copy.deepcopy(result)
|
||||
while len(_BACKTEST_CACHE) > _BACKTEST_CACHE_LIMIT:
|
||||
_BACKTEST_CACHE.pop(next(iter(_BACKTEST_CACHE)))
|
||||
return copy.deepcopy(result)
|
||||
|
||||
|
||||
@@ -720,7 +727,7 @@ def _compute_backtest(ml_mode=False):
|
||||
# Include per-metric values (raw metric value, not score)
|
||||
metric_vals = d.get("metric_values", {})
|
||||
if metric_vals:
|
||||
entry["metrics"] = metric_vals
|
||||
entry["metric_values"] = metric_vals
|
||||
chart_data.append(entry)
|
||||
|
||||
if not ml_mode:
|
||||
|
||||
Reference in New Issue
Block a user