GPU-accelerated parameter sweeps
Updated
A parameter sweep is thousands of independent backtests over the same bars, which is exactly the shape a GPU is built for. One keyword moves the grid onto yours, and the results come back identical to the CPU path, bit for bit. A million backtests, exact, in under four seconds.
Same strategy, same config, same result objects. The device is the only thing that changes.
One keyword, and the grid moves to the GPU
There is no separate GPU API to learn, no array to hand-manage, no second strategy definition to keep in sync. The sweep you already run takes a device.
import manifoldbt as mbt
# A grid of 30,000 combinations over the same bars: 30,000 independent
# backtests, which is exactly the shape a GPU is built for.
sweep = mbt.run_sweep_lite(
strategy,
param_grid={"fast": range(5, 105), "slow": range(20, 320)},
config=config,
store=store,
device="auto", # "cpu", "cuda", or "auto" (the default)
)
sharpe = mbt.sweep_columns(sweep, "sharpe") # one numpy column, no per-combo objects
best = sweep[int(sharpe.argmax())]auto is the default
It decides per sweep. Small grids stay on the CPU, large ones move to the GPU when a build, a device and a license are all available. The threshold is a thousand combinations, and MBT_GPU_AUTO_MIN_COMBOS overrides it.
No silent downgrade
With no GPU, no Researcher license or a CPU-only platform, auto is the CPU sweep and the results are the same, and when a grid that could have used the card stays on the CPU, a warning says why. device="cuda" is the explicit form: a missing license raises, a strategy shape without a kernel warns with its reason, and even a typo in the device string is an error.
Walk-forward too
run_walk_forward takes the same device and decides fold by fold: each fold’s grid goes to the card when it is large enough to pay for the launch, and stays on the CPU when it is not.
The results are ordinary results
Same objects, same metrics, in the grid’s documented order: axes sorted by parameter name, the last one varying fastest. sweep_columns pulls one metric across a million combinations into a numpy array without building a million Python objects.
Where the GPU wins, and where it loses
A GPU is not a multiplier you bolt onto everything. It has a fixed cost to start work and enormous throughput once started, so the honest question is never how fast it is, it is where the two curves cross. Here is that measurement rather than a marketing ratio.
| Grid | CPU | GPU | Winner |
|---|---|---|---|
| 100 combinations | 9.5 ms | 35 ms | CPU 3.7x |
| 1,024 combinations | 71 ms | 44 ms | GPU 1.6x |
| 10,000 combinations | 0.72 s | 0.115 s | GPU 6.3x |
| 250,000 combinations | 18.8 s | 1.95 s | GPU 9.6x |
The flat left half of the GPU line is a floor, not a plateau: uploads, kernel launches and result building that a two-combination sweep pays in full, about 30 ms on these 100,000 bars and 14 ms on 44,000. The first sweep in a process adds about 100 ms for the CUDA context and the strategy’s kernel, and the very first sweep on a new card spends about two seconds calibrating it, once, kept on disk.
Below the crossover the CPU does not merely compete, it wins outright. That is the number most GPU claims leave out, and it is the whole reason device="auto" exists.
The crossing moves with the length of the series: about 940 combinations on 8,760 hourly bars, 590 on these 100,000, 190 on 525,600 minute bars. Auto switches at a thousand combinations, which sits on the crossing for a year of hourly bars and on the cautious side of it for longer series, where a grid of a few hundred combinations would already run faster on the card. MBT_GPU_AUTO_MIN_COMBOS moves the threshold for a workload you know, and device="cuda" takes the card at any size.
Rerun in public with every release
The figures above come from one workstation. The public benchmark reruns the sweep grids of the CPU benchmark on a rented NVIDIA L4, with the wheel from PyPI, and compares every cell with the CPU result. Its CPU column is a four-vCPU GitHub runner, so the ratio reads the runner against the card, not the card against a CPU beside it.
| Bars x combinations | NVIDIA L4 | CPU (runner) | Ratio | Bit-identical |
|---|---|---|---|---|
| 20,000 x 5,000 | 31.1 ms | 367.7 ms | - | 5,000 / 5,000 |
| 20,000 x 20,000 | 107.5 ms | 1.44 s | - | 20,000 / 20,000 |
| 200,000 x 10,000 | 234.1 ms | 6.17 s | - | 10,000 / 10,000 |
| 200,000 x 150,000 | 2.81 s | 128.29 s | - | 150,000 / 150,000 |
manifoldbt 0.35.0, measured 2026-11-16. Method, first-call times and the run itself.
Bit-identical, and proven metric by metric
Speed you cannot trust is not speed. If a GPU sweep ranked combinations even slightly differently, you would have to re-run every candidate on the CPU to believe the ranking, which costs more than the GPU saved. So the default path is not approximate.
f64, and fused multiply-add off
numericsDouble precision, fused multiply-add disabled, exact division and square root. The GPU evaluates the same arithmetic in the same order at the same precision as the CPU engine, and nothing is reassociated for speed: a few percent of throughput traded for an answer that needs no re-checking.
Asserted on the bits, not on a tolerance
testedThe end-to-end suite compares final equity, the trade count and the metrics with raw bit equality across SMA and EMA crossovers, threshold entries, RSI, TRIX, custom sizing, named signals and multi-asset universes. Skewness and kurtosis, the two higher moments, are held to one part in a trillion; everything else is not close, it is equal.
The same random numbers
monte carloThe GPU bootstrap draws from the same seeded generator as the CPU path, verified against fixed reference streams, so one seed produces the same paths on either device and the per-path returns, drawdowns, percentiles and probability of ruin all match exactly.
Scan mode: rank in fp32, decide in f64
Single precision is an opt-in second gear for the single-asset kernel, and it is honest about what it is: a scan. A signal sitting within about 1e-7 of a decision threshold can flip, so individual combinations do diverge from the exact run.
What survives that is the ranking, which is what a scan is for. On a one-million-combination grid, the overlap with the f64 ranking is 100% at the top 10, the top 100 and the top 1,000, the argmax is identical, and the median relative error on the Sharpe ratio is 2.6e-6. The scan runs that million in 1.33 s, against 3.95 s in f64.
So the workflow is explicit rather than implicit: scan wide in fp32, then settle the shortlist in f64, where the numbers are bit-identical to the CPU. fp32 only exists on the GPU and only when you pass precision="fp32": no default ever turns it on.
# Scan: rank the whole grid in single precision.
scan = mbt.run_sweep_lite(
strategy, wide_grid, config, store,
device="cuda", precision="fp32",
)
# Settle: re-run the shortlist in f64, which is exact and bit-identical
# to the CPU. Ranking in fp32, deciding in f64.
final = mbt.run_sweep_lite(strategy, shortlist, config, store, device="cuda")What runs on the GPU, and what tells you when it does not
Not every strategy shape has a kernel. The dangerous version of that is a sweep that quietly runs on the CPU at a twentieth of the speed while you assume the GPU is busy, so a fallback here always says so, and always says why.
- +Arithmetic, comparisons, boolean logic and if/else over any pointwise expression, crossings, value_when and forward fill
- +EMA on any input, SMA, RSI, ROC, z-score, rolling std and rolling sum over a column or a pointwise expression
- +Rolling variance, covariance, correlation and beta, and rolling min and max over a column
- +Scans, including one that carries a swept parameter, such as a Kalman band with its noise swept
- +Exit orders: stop-loss, take-profit and trailing stops on a single-asset universe, with the distance swept like any other parameter
- +Multi-asset universes and perpetual funding on both; exogenous columns on a single-asset universe
- +A fill level the strategy computes, on a single-asset universe: ExecutionPrice.custom() naming one of your own signals is evaluated in the kernel, with or without exit orders, so correct fills cost no throughput
- +Higher timeframes on a single-asset universe: a strategy reading tf("1h") is resampled once on the host and read like any other column
- −Lag and lead, refused on purpose rather than approximated: a missing value and an out-of-range one mean different things to the simulation
- −A windowed indicator nested inside another windowed indicator, and windows measured in time rather than in bars
- −Cross-sectional operations, multi-source data, and higher timeframes on a multi-asset universe
- −Per-venue fees, and exit orders on a multi-asset universe
- −A custom fill level that names a bar column rather than a signal
- −The tick layer: fills resolved on the tape, queue and latency models, and the trade clock, which are served print by print
UserWarning: device="cuda" was requested but this sweep ran
on the CPU: exit orders on a multi-asset universe (the multi kernel
has no bracket). Results are correct and identical either way --
only slower.
# Make a fallback fail your test instead of warning:
with pytest.warns(UserWarning, match="ran on the CPU"):
mbt.run_sweep_lite(strategy, grid, config, store, device="cuda")A fallback is a UserWarning that carries its reason, raised before the CPU starts, and Python’s own deduplication keeps a loop of a thousand identical sweeps to one line. The reasons are stable strings, so a test can match on them, or turn every fallback into a failure.
They are also specific enough to act on. Learning that one stop-loss on a multi-asset universe is what moved your grid back onto the CPU is the difference between rewriting the strategy and shrugging at a slow run.
The refusals are deliberate too. A shape that would run almost right on the GPU stays on the CPU instead, because an answer that is nearly the CPU’s is worse than one that is honestly slower.
Monte Carlo, on the same card
The bootstrap has the same shape as a sweep: many independent resamplings of one return series. The CPU bootstrap is already quick, since it never writes a path it does not keep, so the card does not change what is possible here: it halves the wait on large studies, at daily and at minute resolution alike.
Scaled to a study rather than a demo, ten million paths over a 1-minute equity curve come to about an hour on the card against about two on the CPU, both extrapolated from rates measured up to a million paths. Useful when the study is large; not a reason on its own to buy a card.
Here too the GPU is additive rather than a separate mode. Asking for the trade bootstrap, or for the full paths to be stored, or running without a device at all, simply routes the study back to the CPU, and the numbers that come back are the same ones.
What it takes to turn it on
Three things, and the engine tells you clearly which one is missing.
An NVIDIA GPU
CUDA. Every number on this page was measured on an RTX 3090 with 24 GB, against the 20 threads of an i5-13600KF, with manifoldbt 0.29.0. VRAM decides how much of the grid runs in one pass; beyond that the sweep is chunked automatically, which costs throughput rather than correctness.
Nothing else to install
Since 0.18.0 the standard wheel carries the CUDA kernels on Linux and Windows x86_64, ARM glibc included, so there is no second package to choose between. Platform tags do the sorting, which a package name cannot: pip has no idea whether your machine has a card. macOS and musl stay CPU-only, where the path does not compile. Nothing changes if you have no GPU: the CUDA binary links no NVIDIA library at load time and costs 0.8 MB. One piece is deliberately not in the default install. NVRTC compiles the kernels at runtime, so the card cannot run without it, and it weighs about 180 MB: too much to hand to everyone who types pip install manifoldbt, which is why it sits behind pip install manifoldbt[gpu]. If a CUDA 12 toolkit is already on the machine it supplies NVRTC and you need nothing extra. Miss it and the sweep falls back to the CPU with a warning that the driver or NVRTC could not be loaded, rather than being quietly slow.
A Researcher license
Without one, device="cuda" raises a LicenseError that names the plan, and device="auto" runs the CPU sweep, with a warning when a card is present and the grid is large enough to have used it. The results are the same either way: the GPU is an extra path, never a different answer.
See what Researcher includes →FAQ
Explore the rest of the engine
Every capability is documented the same way: what it does, the code that runs it, and the case where it is the wrong tool.
- The Rust Backtesting Engine
A million bars in 22 ms on one core, a grid swept 25x faster than the same backtests one at a time, and where that advantage stops.
- The Expression DSL
Signals declared as composable expressions and evaluated vectorized in Rust: 104 indicators, 38 candlestick patterns, 74 methods, cross-asset references, parameters that sweep.
- The Research Workflow
Parameter maps, stability scores, walk-forward folds, Monte Carlo resampling and look-ahead detection, each answering a question one backtest cannot.
- Realistic Slippage, Fees and Funding
Slippage, fees, funding, borrow, partial fills and decision-to-fill delay, each an independent model rather than one flat cost assumption.
- Multi-Asset Backtesting
Rank a universe on every bar and trade the cross-section: nine perpetuals in one call, one shared account, portfolio-level exposure and fees.
- Options Backtesting
Contracts that expire, cash-settle at intrinsic value, and post margin under a named model: a real multi-leg spread, held to expiry, on live Deribit data.
Sweep the whole map, not a corner of it
A parameter map you can redraw in seconds is a map you actually read. That is the habit the GPU buys, and the one that keeps a strategy from being tuned into a single lucky point.