# PyBroker

Python backtester with walk-forward model training and bootstrapped confidence bounds.

**Best for:** Python developers testing a model they trained themselves as a trading rule on daily or intraday bars; not for anyone who needs live order routing, options or futures, or an OSI open-source licence.

*https://stockmarketstack.com/tools/pybroker · Backtesting Frameworks & Algo Trading Libraries*

## Facts

### At a glance

| Field | Value |
| --- | --- |
| Vendor | Edward West |
| Category | Backtesting Frameworks & Algo Trading Libraries |
| Job | backtesting |
| Website | https://www.pybroker.com |
| Pricing model | free |
| Free tier | true |
| Open source | false |
| Licence | Apache-2.0 with Commons Clause |
| Self-hosted | true |
| Tested hands-on | no |
| Claimed by vendor | no |
| Last updated | 2026-10-07 |

### Coverage

| Field | Value |
| --- | --- |
| Asset classes | stocks, etf, crypto |
| Markets | global |
| Works outside the US | true |
| Data latency | none |
| Platforms | library |
| AI features | none |

### Interfaces

| Field | Value |
| --- | --- |
| API | false |
| Webhooks | false |
| Scripting | Python |
| Python | true |
| Spreadsheet add-in | false |
| MCP server | false |
| Export | json |

### Capabilities

Yes: backtesting

No: charting, screening, scanning, automation, live_trading, paper_trading, portfolio_tracking, broker_import, tax_reporting, alerts, news, options_analysis

*Verified: pricing 2026-10-07; capabilities 2026-10-07; coverage 2026-10-07.*

## What it is

PyBroker is a Python backtesting framework built around models rather than rules. You register a
training function, and PyBroker calls it with each symbol's training data. It then backtests an
execution function that reads the model's predictions bar by bar, through `ctx.preds()`, alongside
indicators, positions and pending orders. The engine is event-driven per bar and per symbol, with
NumPy and Numba under it. It handles long and short positions, stops, limit orders, margin,
rotation and ranking across a universe.

Two features set it apart from the rest of this category. `walkforward()` splits the history into
a fixed number of windows, each with its own train/test split. It retrains the model per window
and moves forward in time, adding each window's test data to the next window's training set, with
a `lookahead` setting to stop labels leaking across the boundary. `calc_bootstrap=True` then reports
confidence bounds for the Sharpe ratio and profit factor, plus drawdown probabilities, rather than
a single number from one path.

The repository is not archived. The last release is v2.0.1 (28 August 2026), after v2.0.0 on 17
August 2026, and the last commit to master was the same day. It has about 3,570 stars and no open
issues against 143 closed ones. The ten open pull requests are all Dependabot's. One author wrote
about 90% of the commits.

## Pricing

Free, with no account, tier or paid edition. The licence is the thing to read instead: Apache 2.0
with the Commons Clause v1.0, the same arrangement as [VectorBT](https://stockmarketstack.com/tools/vectorbt), which makes it
source-available rather than OSI open source.

## Data & coverage

Built-in sources are `YFinance`, `YQuery` (yahooquery), `Alpaca` for US stocks and `AlpacaCrypto`,
with `AKShare` for China in an extension module. Since 2.0.0, AKShare is no longer installed with
the package, so you install it yourself. Any pandas DataFrame with symbol, date and OHLC columns
works as a source, and custom columns can be registered for use inside the strategy. Downloads,
indicators and trained models can be cached to disk. The engine models shares, not contracts:
there is no options chain, futures multiplier or roll.

## Integrations

Optuna for parameter search (`hyperparam` and `Strategy.optimize`), joblib for parallel indicator
and model work with Ray as an optional backend, and any model library you can call from a training
function. scikit-learn, gradient-boosting and time-series models appear in the docs. Results are
pandas DataFrames, and 2.0.0 added `to_json()`. The repo also ships six Agent Skills, which are
`SKILL.md` instruction files that teach a coding agent such as Claude Code, Codex or Cursor to
write PyBroker strategies. They are not an AI feature of the library itself.

## Limitations

- The defaults are kind to a backtest. An order is placed one bar after its signal and fills at
  that bar's midpoint, (high + low) / 2, with fees at zero until you set `fee_mode`. Set the fill
  price and fees explicitly before you believe a number.
- The bootstrap draws bars independently, with no blocks. That shuffles away serial correlation and
  volatility clustering, so the drawdown bounds assume the path does not matter.
- There is no live trading, no paper account and no broker adapter.
- The licence is not OSI open source, and the PyPI classifier misstates it (see the FAQ).
- Python 3.11 or newer for 2.x. The 1.2 line, last released as 1.2.14, supported 3.10.

## Alternatives

[VectorBT](https://stockmarketstack.com/tools/vectorbt) is much faster for sweeping rules but has no walk-forward model
harness. [Backtesting.py](https://stockmarketstack.com/tools/backtesting-py) is smaller and single-asset. [Qlib](https://stockmarketstack.com/tools/qlib)
is the choice when the model is a cross-sectional factor ranker over an index.
[NautilusTrader](https://stockmarketstack.com/tools/nautilus-trader) and [Lumibot](https://stockmarketstack.com/tools/lumibot) are the ones to look at when
the same code has to place real orders. [Kronos](https://stockmarketstack.com/tools/kronos) is the opposite starting point:
pre-trained open weights that generate bars, with no backtester of its own, rather than a model
you train per window.

## FAQ

### Is `pip install pybroker` the right install?

No. The package is `lib-pybroker`, and on 7 October 2026 PyPI had no project called `pybroker` at all, so the obvious command fails rather than installing somebody else's code. The current release is 2.0.1, uploaded 28 August 2026, and it requires Python 3.11 or newer.

### Can a company use PyBroker?

To trade its own capital, the licence allows it. It is Apache 2.0 with the Commons Clause, which withholds only the right to Sell, meaning to charge third parties for a product or service whose value derives substantially from the software. The PyPI classifier reads "Free for non-commercial use", which is narrower than the LICENSE file. The LICENSE is the text that binds, and the author is the person to ask about a paid service built on it.

### Can PyBroker place live trades?

No. Nothing in the source submits an order to a broker. Alpaca appears only as a data source for historical stock and crypto bars, and the portfolio is a simulator.

### Do results from PyBroker 1.x still stand?

Rerun them. Version 2.0.0, released 17 August 2026, corrected the Calmar ratio, the Ulcer Index, unrealised PnL (previously understated by total fees) and the annualised return interval count. It also changed the bootstrap to resample the full return series after finding cases that produced incorrect confidence intervals.

## Also worth comparing

- [Blueshift](https://stockmarketstack.com/tools/blueshift.md) — Free hosted Python backtesting with bundled minute data and broker execution.
- [VectorBT](https://stockmarketstack.com/tools/vectorbt.md) — Vectorised backtesting — thousands of parameter combinations in one NumPy pass.
- [AmiBroker](https://stockmarketstack.com/tools/amibroker.md) — Windows portfolio backtester scripted in AFL, sold as a perpetual licence.
- [Backtesting.py](https://stockmarketstack.com/tools/backtesting-py.md) — A single-instrument Python backtester — one OHLC series, one strategy, no live trading.
- [Backtrader](https://stockmarketstack.com/tools/backtrader.md) — An event-driven Python backtester with 122 indicators, frozen since April 2023.
- [bt](https://stockmarketstack.com/tools/bt.md) — Python backtesting for allocation and rebalancing rules, not entries and exits.
