Commit d142374
committed
perf(metrics): O(N^2) -> O(N) snapshot lookup in rolling Sharpe
get_rolling_sharpe_ratio used next((s for s in snapshots if
s.created_at == date), None) once per output row, scanning the
full snapshot list every time. With ~7600 daily rows this was
roughly 47% of recalculate_backtests() runtime in profiling.
Replaced with a one-shot {created_at: snapshot} dict lookup.
End-to-end recalculate_backtests on the 6-strategy x 11-runs
example batch: 20.8s -> 10.9s (~1.9x). recalculate_backtests
itself is unchanged and works on bundle- and legacy-loaded
backtests identically since it operates on Backtest objects.1 parent d723f3e commit d142374
1 file changed
Lines changed: 6 additions & 2 deletions
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
124 | 129 | | |
125 | 130 | | |
126 | 131 | | |
127 | 132 | | |
128 | 133 | | |
129 | 134 | | |
130 | 135 | | |
131 | | - | |
132 | | - | |
| 136 | + | |
133 | 137 | | |
134 | 138 | | |
135 | 139 | | |
| |||
0 commit comments