fix(backtest): one window, and stop calling a rejected exit "recommended"
Two ways the recommendation still disagreed with the page it sits on. It preferred the "all" monitor row while the UI defaulted its selector to "3y", so a default page load showed one set of returns in the tiles and a different set in the recommendation. The row it used is now published as basis_lookback and the page defaults to it, so the two cannot open on different windows. The test fixture gains a second monitor row with different numbers — with only an "all" row present, a lookback mix-up could not fail. Robustness picked its basis between "the recommended Nd hold" and "the S/R target exit", naming an exit the production book replaced as recommended. There is no ATR-trail ex-top-5% figure in the report, so it now always reports the gate-level grading and says that is what it is, rather than dressing a legacy number as a verdict on the production book. time_exit_sweep is no longer read here at all. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -3944,14 +3944,11 @@ def _build_recommendation(report: dict) -> dict:
|
||||
})
|
||||
|
||||
q = report.get("overall_qualified") or {}
|
||||
target_net = q.get("net_avg_r")
|
||||
|
||||
# The best fixed hold, kept ONLY to pick the basis for the robustness check
|
||||
# below. The hold-vs-target comparison itself is deliberately not reported:
|
||||
# both are legacy exits the production book replaced with the ATR trail, so
|
||||
# a recommendation between them could not lead to an action.
|
||||
time_rows = [r for r in report.get("time_exit_sweep") or [] if r.get("net_avg_r") is not None]
|
||||
best_hold = max(time_rows, key=lambda r: r["net_avg_r"], default=None)
|
||||
# Nothing here reads time_exit_sweep any more. The hold-vs-target comparison
|
||||
# is not reported (both are exits the production book replaced, so choosing
|
||||
# between them cannot lead to an action), and the robustness check below no
|
||||
# longer picks its basis from them either.
|
||||
|
||||
# Gate floors, judged under the hold exit (the ablation's Hold column).
|
||||
ablation = {r["variant"]: r for r in report.get("gate_ablation") or []}
|
||||
@@ -4016,19 +4013,15 @@ def _build_recommendation(report: dict) -> dict:
|
||||
),
|
||||
})
|
||||
|
||||
# Robustness: does the edge survive without the biggest winners? Judged on
|
||||
# the RECOMMENDED exit — outlier dependence under an exit we'd abandon
|
||||
# would be the wrong warning.
|
||||
hold_recommended = (
|
||||
best_hold is not None and target_net is not None
|
||||
and best_hold["net_avg_r"] > target_net + _EXIT_SWITCH_THRESHOLD
|
||||
)
|
||||
if hold_recommended and best_hold.get("net_avg_r_ex_top5") is not None:
|
||||
trimmed = best_hold["net_avg_r_ex_top5"]
|
||||
basis = f"under the recommended {best_hold['hold_days']}d hold"
|
||||
else:
|
||||
trimmed = q.get("net_avg_r_ex_top5")
|
||||
basis = "under the S/R target exit"
|
||||
# Robustness: does the edge survive without the biggest winners?
|
||||
#
|
||||
# There is no ATR-trail equivalent of this number in the report — the only
|
||||
# ex-top-5% figure is the gate-level target/stop grading. So it is reported
|
||||
# on that basis and SAYS SO, rather than being dressed up as a verdict on the
|
||||
# production book. It used to pick between "the recommended Nd hold" and "the
|
||||
# S/R target exit", naming a rejected exit as recommended.
|
||||
trimmed = q.get("net_avg_r_ex_top5")
|
||||
basis = "gate-level grading, not the production ATR-trail book"
|
||||
if trimmed is not None:
|
||||
if trimmed > 0:
|
||||
items.append({
|
||||
@@ -4057,6 +4050,12 @@ def _build_recommendation(report: dict) -> dict:
|
||||
return {
|
||||
"headline": headline,
|
||||
"items": items,
|
||||
# Which monitor row every production/benchmark figure above was read
|
||||
# from. The page defaults its lookback selector to this, so the tiles and
|
||||
# the recommendation cannot open on different windows — they used to,
|
||||
# because this preferred "all" while the UI defaulted to "3y".
|
||||
"basis_lookback": (production_row or {}).get("lookback"),
|
||||
"basis_lookback_label": (production_row or {}).get("lookback_label"),
|
||||
"note": "Derived from this report's numbers on every run — the advice flips if the data does.",
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user