You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docusaurus/docs/Getting Started/backtest-reports.md
+54-28Lines changed: 54 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -84,46 +84,51 @@ report.show()
84
84
85
85
## Recalculating Metrics
86
86
87
-
When metric calculations are updated in a newer framework version, previously saved backtests may have stale metrics. Use `recalculate_backtests` to recompute all per-run and summary metrics from the raw portfolio snapshots and trades:
87
+
When metric calculations are updated in a newer framework version, previously saved backtests may have stale metrics. Use `recalculate_backtests_in_directory` to recompute all per-run and summary metrics from the raw portfolio snapshots and trades — **directly on disk**, without ever loading the full set of backtests into memory:
88
88
89
89
```python
90
-
from investing_algorithm_framework importBacktestReport, recalculate_backtests
90
+
from investing_algorithm_framework importrecalculate_backtests_in_directory
You can specify a custom risk-free rate (otherwise each backtest's stored rate is used):
96
+
Each backtest is loaded, recalculated, and written back **inside a worker process**, so the parent process's memory footprint stays flat regardless of how many backtests are processed. This is the recommended approach for any non-trivial batch (hundreds to thousands of backtests with portfolio snapshots and trades can otherwise consume tens of GB).
97
+
98
+
Write to a different directory instead of in place:
The in-memory variant `recalculate_backtests(backtests)` is **deprecated since 8.7.2** and will be removed in a future major release. Holding many backtests in the parent process is memory-unsafe — each `Backtest` carries portfolio snapshots, trades and timeseries, so a list of a few thousand backtests can easily consume tens of GB before any work starts. Use `recalculate_backtests_in_directory(src_dir, ...)` instead.
131
+
:::
127
132
128
133
## Saving Reports
129
134
@@ -191,7 +196,8 @@ Toggle between dark and light mode using the sun icon in the top-right corner.
|`report.show(browser=False)`| Display the report. In Jupyter: renders inline. Otherwise: opens browser. Set `browser=True` to force browser. |
240
246
|`report.save(path)`| Save the report as a self-contained HTML file |
241
247
242
-
### `recalculate_backtests`
248
+
### `recalculate_backtests_in_directory`
249
+
250
+
Stream-recalculates every backtest bundle on disk inside worker processes. The full `Backtest` never crosses the process boundary, so parent memory stays flat.
|`dst_dir`|`str \| Path`, optional | Output directory. If `None`, bundles are rewritten in place inside `src_dir`|
256
+
|`risk_free_rate`|`float`, optional | Override risk-free rate. If `None`, uses each backtest's stored rate |
257
+
|`metrics`|`List[str]`, optional | Specific metrics to compute. If `None`, computes all default metrics |
258
+
|`workers`|`int`, optional | Number of parallel worker processes. Defaults to `min(8, cpu_count)`. Pass `1` for serial |
259
+
|`show_progress`|`bool`| Display a tqdm progress bar (default `False`) |
260
+
|`include_ohlcv`|`bool`| Re-emit attached OHLCV data with the bundle (default `False`) |
261
+
|`max_tasks_per_child`|`int`, optional | Recycle each worker after this many tasks so RSS stays bounded (default `16`) |
262
+
|`update_index`|`bool`| Rewrite `index.parquet` in the destination directory (default `True`) |
263
+
264
+
**Returns:**`int` — the number of backtests recalculated.
265
+
266
+
### `recalculate_backtests`*(deprecated)*
267
+
268
+
:::warning Deprecated since 8.7.2
269
+
Use [`recalculate_backtests_in_directory`](#recalculate_backtests_in_directory) instead. This in-memory variant will be removed in a future major release.
270
+
:::
243
271
244
272
| Parameter | Type | Description |
245
273
|-----------|------|-------------|
@@ -248,5 +276,3 @@ report.show(browser=True)
248
276
|`metrics`|`List[str]`, optional | Specific metrics to compute. If `None`, computes all default metrics |
249
277
250
278
**Returns:**`List[Backtest]` — the same backtest objects with updated metrics.
251
-
252
-
Recalculates all per-run `BacktestMetrics` from raw portfolio snapshots and trades, then regenerates `BacktestSummaryMetrics` for each backtest.
0 commit comments