Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions bench/BENCH_EVOLUTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Bench: harness evolution ideas (selection rules under sealed holdout)

Protocol identical across rules: SPY daily, search = first 80% (2021-12-03..2025-12-02),
sealed trailing 20% holdout graded once, harness `basic_momentum_backtest` engine.
Pools: 10-point momentum grid, and the two deepseek-v4-1-flash-1017 proposal sets from
bench/BENCH_DEEPSSEEK_V4_1_FLASH.md.

| Pool | raw-Sharpe pick (holdout) | DSR pick (holdout) | top-3 ensemble (holdout) | cost-loaded pick (holdout, cost-free) |
| --- | --- | --- | --- | --- |
| grid | 63/252 (-0.349) | 63/252 (-0.349) | 63/252+5/20+50/150 (-1.030) | 63/252 (-0.349) |
| deepseek run1 | 30/150 (-0.194) | 30/150 (-0.194) | 30/150+10/50+50/200 (-0.958) | 30/150 (-0.194) |
| deepseek run2 | 10/50 (+0.169) | 10/50 (+0.169) | 10/50+50/200+15/80 (-0.040) | 50/200 (-0.186) |

Caveats (open, found in review):
- The pick tables above were produced by the bench's own scoring path, which is not
committed. Until the harness fed `n_obs`/`skew`/`kurt` to selection (it now derives
them from the equity curve), `agent.selection: dsr` ranked identically to `sharpe`
in the live harness, so "DSR never changed the pick" says nothing about DSR itself.
Re-run with the instrumented path before citing it.
- `is_costed_sharpe` exceeds the cost-free in-sample Sharpe for the same config
(grid 1.052 vs 1.039, run1 1.070 vs 0.947); costs should only lower it. The grid
`holdout_costed` entry is all zeros. Drawdown signs differ between costed and
cost-free rows. Treat the cost-loaded column as unverified.
- Both top-3 ensemble rows for deepseek run1/run2 report the identical
`wf_median_sharpe` (0.0867); check for a copy error.
- The holdout is compared across several rules and pools, so it is validation data
for this comparison, not a fresh one-shot grade.

Findings:
- DSR selection never changed the pick here: with equal sample sizes across trials,
deflated Sharpe is monotonic in raw Sharpe, so it only re-ranks when trials differ
in n_obs/skew/kurt. Its real value is at the promotion gate (already in src/gate),
not in tournament ranking. Wired into the harness as `agent.selection: dsr` anyway
(branch evolve/dsr-selection-pr); default stays `sharpe`.
- Top-3 signal ensemble was worse on this holdout — averaging a strong winner with two
weaker configs dilutes it.
- Cost-loaded selection picked lower-turnover configs (good hygiene) but did not beat
raw selection on this single holdout.
- Honest conclusion: on one SPY slice, no selection rule dominates; the sealed-holdout
gate remains the only trustworthy score, which is the harness's core claim.
Full data: bench/bench_evolution_report.json
232 changes: 232 additions & 0 deletions bench/bench_evolution_report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
{
"protocol": "SPY daily; search = first 80% (2021-12-03..2025-12-02); sealed holdout = trailing 20% graded once; engine = harness basic_momentum_backtest",
"pools": {
"grid": {
"raw_sharpe_pick": {
"params": {
"fast_window": 63,
"slow_window": 252
},
"is_sharpe": 1.039257737894098,
"holdout": {
"sharpe": -0.34889937596579557,
"total_return": -0.05188612295784234,
"max_drawdown": 0.1225143697875436,
"num_trades": 1
},
"wf_median_sharpe": 0.0,
"is_holdout_gap": 1.3882
},
"dsr_pick": {
"params": {
"fast_window": 63,
"slow_window": 252
},
"is_sharpe": 1.039257737894098,
"holdout": {
"sharpe": -0.34889937596579557,
"total_return": -0.05188612295784234,
"max_drawdown": 0.1225143697875436,
"num_trades": 1
},
"wf_median_sharpe": 0.0,
"is_holdout_gap": 1.3882
},
"top3_ensemble": {
"params": [
{
"fast_window": 63,
"slow_window": 252
},
{
"fast_window": 5,
"slow_window": 20
},
{
"fast_window": 50,
"slow_window": 150
}
],
"is_sharpe": 0.9558316023594263,
"holdout": {
"sharpe": -1.0304906614078204,
"total_return": -0.037532964897971866,
"max_drawdown": -0.04236736981634448,
"num_trades": 3
},
"wf_median_sharpe": 0.0,
"is_holdout_gap": 1.9863
}
},
"deepseek_run1": {
"raw_sharpe_pick": {
"params": {
"fast_window": 30,
"slow_window": 150
},
"is_sharpe": 0.9472587017916024,
"holdout": {
"sharpe": -0.19443527067321684,
"total_return": -0.03389981634895789,
"max_drawdown": 0.1145952665537557,
"num_trades": 2
},
"wf_median_sharpe": 1.3592136492876792,
"is_holdout_gap": 1.1417
},
"dsr_pick": {
"params": {
"fast_window": 30,
"slow_window": 150
},
"is_sharpe": 0.9472587017916024,
"holdout": {
"sharpe": -0.19443527067321684,
"total_return": -0.03389981634895789,
"max_drawdown": 0.1145952665537557,
"num_trades": 2
},
"wf_median_sharpe": 1.3592136492876792,
"is_holdout_gap": 1.1417
},
"top3_ensemble": {
"params": [
{
"fast_window": 30,
"slow_window": 150
},
{
"fast_window": 10,
"slow_window": 50
},
{
"fast_window": 50,
"slow_window": 200
}
],
"is_sharpe": 0.8636604970039298,
"holdout": {
"sharpe": -0.9581071420607912,
"total_return": -0.09816813724340434,
"max_drawdown": -0.13200415173610036,
"num_trades": 2
},
"wf_median_sharpe": 0.08669341670217345,
"is_holdout_gap": 1.8218
}
},
"deepseek_run2": {
"raw_sharpe_pick": {
"params": {
"fast_window": 10,
"slow_window": 50
},
"is_sharpe": 0.828833410649044,
"holdout": {
"sharpe": 0.16948588746394266,
"total_return": 0.011646057672553,
"max_drawdown": 0.05685387979983793,
"num_trades": 4
},
"wf_median_sharpe": -0.15052921662986785,
"is_holdout_gap": 0.6593
},
"dsr_pick": {
"params": {
"fast_window": 10,
"slow_window": 50
},
"is_sharpe": 0.828833410649044,
"holdout": {
"sharpe": 0.16948588746394266,
"total_return": 0.011646057672553,
"max_drawdown": 0.05685387979983793,
"num_trades": 4
},
"wf_median_sharpe": -0.15052921662986785,
"is_holdout_gap": 0.6593
},
"top3_ensemble": {
"params": [
{
"fast_window": 10,
"slow_window": 50
},
{
"fast_window": 50,
"slow_window": 200
},
{
"fast_window": 15,
"slow_window": 80
}
],
"is_sharpe": 0.7382792540641175,
"holdout": {
"sharpe": -0.04048282762396182,
"total_return": -0.0084703325041382,
"max_drawdown": -0.08090604197824491,
"num_trades": 2
},
"wf_median_sharpe": 0.08669341670217345,
"is_holdout_gap": 0.7788
}
}
},
"cost_loaded_selection": {
"grid": {
"pick": {
"fast_window": 63,
"slow_window": 252
},
"is_costed_sharpe": 1.0516824088850143,
"holdout_costed": {
"sharpe": 0.0,
"total_return": 0.0,
"max_drawdown": 0.0,
"num_trades": 0
},
"holdout_cost_free": {
"sharpe": -0.3488985903123744,
"max_drawdown": 0.12251444936615911,
"num_trades": 1
}
},
"deepseek_run1": {
"pick": {
"fast_window": 30,
"slow_window": 150
},
"is_costed_sharpe": 1.0699819975806917,
"holdout_costed": {
"sharpe": -0.4219924640417806,
"total_return": -0.04945429931394385,
"max_drawdown": -0.11459526655375574,
"num_trades": 1
},
"holdout_cost_free": {
"sharpe": -0.1944360362913093,
"max_drawdown": 0.11459526655375593,
"num_trades": 2
}
},
"deepseek_run2": {
"pick": {
"fast_window": 50,
"slow_window": 200
},
"is_costed_sharpe": 0.8548990849394594,
"holdout_costed": {
"sharpe": -0.43967686388861527,
"total_return": -0.0453566896226385,
"max_drawdown": -0.11459526655375574,
"num_trades": 0
},
"holdout_cost_free": {
"sharpe": -0.18619664703419822,
"max_drawdown": 0.11459526655375592,
"num_trades": 1
}
}
}
}
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ agent:
mode: "suggest_only"
holdout_fraction: 0.2 # trailing slice of history the search loop never sees;
# final accept/reject is graded on this once, not re-asked
selection: "sharpe" # tournament selection rule: "sharpe" (raw in-sample Sharpe)
# or "dsr" (deflated Sharpe; penalizes winners of large trial families)
risk:
max_drawdown: 0.20
max_position_size: 0.50
Expand Down
19 changes: 12 additions & 7 deletions src/agent/agent_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,19 +502,24 @@ def backtest_node(state: AgentState) -> AgentState:
except Exception:
logger.warning("Failed to record trials in memory", exc_info=True)

# Sort by Sharpe
# Sort by Sharpe for reporting; the winner is chosen by the configured
# selection rule (raw Sharpe by default, deflated Sharpe to penalize
# multiple-testing winners — see src/agent/selection.py).
results.sort(key=lambda x: x.get("sharpe", 0.0), reverse=True)
state["results"] = results
state["all_results"] = state.get("all_results", []) + results

if results:
best = results[0]
from src.agent.selection import select_best
mode = config.agent.selection
family = state["all_results"] # every trial so far, for the DSR hurdle
best = select_best(results, mode=mode, family=family)
previous_best = state.get("best_result")
if previous_best is not None and previous_best.get("sharpe", float("-inf")) > best.get("sharpe", float("-inf")):
# Keep the best candidate seen across all iterations. Previously this
# was overwritten each round, so a worse later iteration replaced the
# winner that holdout grading and storage then used.
best = previous_best
if previous_best is not None:
# Keep the best candidate seen across all iterations (a worse later
# round must not replace the winner holdout grading uses), judged by
# the same selection rule as the per-round pick.
best = select_best([best, previous_best], mode=mode, family=family)
state["best_result"] = best
state["run_log"].append(
f"Best: Sharpe={best['sharpe']:.2f}, Return={best['total_return']:.1%}, "
Expand Down
Loading
Loading