📈 GH Trending Explorer 🎲 Surprise me

← all repos

edtechre / pybroker

git clone https://github.com/edtechre/pybroker.git v2.0.2 · 2d ago

Algorithmic Trading in Python with Machine Learning

+6
stars, 24h · #2,365
+~42
stars, 7 days · #2,930
+~180
stars, 30 days · #2,897
3.6k
★ total · +1% this week
458
forks · 0 open issues

Star history (as recorded here)

2026-10-20 · 3,621 ★ 2026-10-22 · 3,633 ★
LanguagePython
License—
Created2023-01-16 (3y ago)
Last push2d ago
Watchers44
OwnerUser

GitHub topics

Links

README excerpt
## Algorithmic Trading in Python with Machine Learning
Are you looking to enhance your trading strategies with the power of Python and
machine learning? **PyBroker** is a Python framework
designed for developing algorithmic trading strategies, with a focus on
strategies that use machine learning. With PyBroker, you can easily create and
fine-tune trading rules, build powerful models, and gain valuable insights into
your strategy’s performance.
## Key Features
* A super-fast backtesting engine built in NumPy and accelerated with Numba.
* Easy creation of trading rules and models for executing across multiple instruments.
* Integration of trading signals across multiple time intervals, including daily, weekly, and monthly.
* Access to historical data from Alpaca, Yahoo Finance, AKShare, or from your own data provider.
* Model training and backtesting using Walkforward Analysis, which simulates how the strategy would perform during actual trading.
* Reliable trading metrics that use randomized bootstrapping) to provide more accurate results.
* Parameter optimization with Optuna to select the best strategy parameters.
* Caching of downloaded data, indicators, and models to speed up your development process.
* Parallelized computation and training for faster performance.
* Agent Skills that help AI agents write trading strategies and backtests using PyBroker.
PyBroker provides you with the tools to build, test, and evaluate algorithmic trading strategies backed by machine learning.
## Installation
PyBroker supports Python 3.11+ on Windows, Mac, and Linux. You can install
PyBroker using ``pip``:
 [code] 
Or you can clone the Git repository with:
 [code] 
## A Quick Example
Here's a glimpse of what backtesting with PyBroker looks like with these code
snippets:
**Rule-based Strategy**:
 [code] 
**Model-based Strategy**:
```python
 import pybroker
 from pybroker import Alpaca, Strategy
 def train_fn(symbol, train_data, test_data):
 # Train the model using indicators stored in train_data.
 ...
 return trained_model
 # Register the model and its training function with PyBroker.
 my_model = pybroker.model('my_model', train_fn, indicators=[...])
 def exec_fn(ctx):
 preds = ctx.preds('my_model')
 if not ctx.long_pos() and preds[-1] > buy_threshold:
 ctx.buy_shares = 100
 elif ctx.long_pos() and preds[-1]