Quick answer
PyAlgoTrade was one of the first popular event-driven backtesting libraries for Python, with technical indicators, optimizers and Bitstamp live trading. Its repository was archived and made read-only in November 2023. The author recommends Basana; Backtrader, backtesting.py and NautilusTrader are other common replacements.
PyAlgoTrade at a glance
- Category
- Backtest + live trading engines
- Language
- Python
- License
- Apache-2.0
- Does
- Backtesting, Optimization
- Markets
- Stocks, Crypto
- Best for
- Reading old tutorials and migrating legacy code; not new projects.
- In AlgoGP
- Use the exported strategy object from your own code
Pick it if
Reading old tutorials and migrating legacy code; not new projects.
Watch out for
Archived: no fixes for new Python or pandas versions.
PyAlgoTrade strengths and limitations
Strengths
- Simple event-driven API that influenced later libraries.
- Built-in parallel optimizer.
Limitations
- Archived: no fixes for new Python or pandas versions.
- Limited live trading.
PyAlgoTrade example
pip install pyalgotrade # archived; Python 3 support is limitedfrom pyalgotrade import strategy
class MyStrategy(strategy.BacktestingStrategy):
def onBars(self, bars):
bar = bars[self.instrument]
self.info(bar.getClose())Use PyAlgoTrade with AlgoGP
AlgoGP does not add PyAlgoTrade to projects automatically yet, but nothing stops you using them together. Every AlgoGP project exports plain Python with a framework-neutral strategy object, so you can call it from PyAlgoTrade yourself.
- 1
Design and backtest in AlgoGP
Describe the idea to the copilot and backtest it on AlgoGP’s normalized history.
- 2
Add any bridge to get the adapter core
Adding a bridged framework (for example Backtrader) writes
frameworks/algogp_bridge.py, whoseStrategyBridge.on_bar()returns the orders the strategy wants. - 3
Call it from PyAlgoTrade
Feed PyAlgoTrade’s bars to
StrategyBridge, place the returned orders with PyAlgoTrade, and report fills back withsync().
PyAlgoTrade connects to Bitstamp. Each guide shows how to create the API key, which you can store in the project’s Keys & secrets.
PyAlgoTrade: frequently asked questions
Does PyAlgoTrade work on Python 3?
Partially, through community forks; the official project is archived.
What is the best PyAlgoTrade alternative?
Basana (same author) for crypto, Backtrader for a similar event-driven API, backtesting.py for simplicity.
PyAlgoTrade alternatives
- BasanaPythonAsync, event-driven Python framework for crypto backtesting and live trading on Binance and Bitstamp, from the author of PyAlgoTrade.
- BacktraderPythonThe classic Python event-driven backtesting library: Cerebro, data feeds, analyzers, sizers and plotting, with live stores for IB and OANDA.
- backtesting.pyPythonSmall, fast Python backtesting library: subclass Strategy, call Backtest.run(), get stats, an interactive Bokeh chart and built-in optimization.
- NautilusTraderPython, RustHigh-performance, Rust-core trading platform with a Python API: the same strategy runs in a nanosecond-resolution backtester and live across many venues.
Independent guide. AlgoGP is not affiliated with PyAlgoTrade. Features, licenses and maintenance change; check the official documentation. Nothing here is investment advice.