Archived

PyAlgoTrade guide

Many tutorials still use PyAlgoTrade, but new projects should start on a maintained framework.

Last reviewed

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 limited
Install
from pyalgotrade import strategy

class MyStrategy(strategy.BacktestingStrategy):
    def onBars(self, bars):
        bar = bars[self.instrument]
        self.info(bar.getClose())
Classic PyAlgoTrade strategy shape.

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. 1

    Design and backtest in AlgoGP

    Describe the idea to the copilot and backtest it on AlgoGP’s normalized history.

  2. 2

    Add any bridge to get the adapter core

    Adding a bridged framework (for example Backtrader) writes frameworks/algogp_bridge.py, whose StrategyBridge.on_bar() returns the orders the strategy wants.

  3. 3

    Call it from PyAlgoTrade

    Feed PyAlgoTrade’s bars to StrategyBridge, place the returned orders with PyAlgoTrade, and report fills back with sync().

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

Independent guide. AlgoGP is not affiliated with PyAlgoTrade. Features, licenses and maintenance change; check the official documentation. Nothing here is investment advice.

Build a strategy