Skip to main content

AlgoChains - Quant backtesting library for algorithmic trading

Project description

AlgoChains

A Python quant backtesting library built on Backtrader, with hosted historical data for Forex, Stocks, and Crypto.


Install

python3 -m venv venv && source venv/bin/activate
pip install algochains
algochains==1.0.0bX

Verify:

python -c "import algochains; print(algochains.__version__)"

Update:

pip install --upgrade algochains

Quickstart

from dotenv import load_dotenv
import os
from algochains import backtest_query
import backtrader as bt

load_dotenv()

class RSI_Strategy(bt.Strategy):
    params = (('symbol', 'UNKNOWN'), ('warmup', 50))

    def __init__(self):
        self.rsi   = bt.indicators.RSI(self.data.close, period=14)
        self.order = None

    def next(self):
        if self.order:
            return
        if not self.position:
            if self.rsi[0] < 30:
                size = int((self.broker.getcash() * 0.95) / self.data.close[0])
                self.order = self.buy(size=size)
        else:
            if self.rsi[0] > 70:
                self.order = self.sell(size=self.position.size)

backtest_query(RSI_Strategy, 10000, "BTC-USD", "2025-01-01", "2025-12-31", "Crypto", "1h",
           api_key=os.getenv("ALGOCHAINS_API_KEY"))

.env file in your project root:

ALGOCHAINS_API_KEY=your_key_here

Supported markets

database examples resolutions
"Forex" "EUR-USD", "GBP-JPY" 1m1d
"Stocks" "AAPL", "TSLA" 1m1d
"Crypto" "BTC-USD", "ETH-USD" 1m1d

Documentation

Full docs live in docs/:

Installation Setup and updates
Core Concepts Warmup, asset classes, commissions, order flow
Strategy API How to write a strategy, sizing, multi-asset
Backtesting backtest_query, optimization, research_query
Data Feeds Historical data, resampling
Troubleshooting Common errors and fixes
LLM Context Paste into your AI assistant for best results

Examples

Ready-to-run strategies in examples/:

File Description
simple_sma_cross.py SMA crossover on Stocks
rsi_strategy.py RSI mean-reversion on Forex
walkforward_optuna.py Parameter optimization with Optuna

Using with an AI assistant

If you are using an AI assistant (Claude, ChatGPT, Copilot, Cursor, etc.), start your session with:

"Get familiar with the AlgoChains library by reading AGENTS.md before we start working."

Your agent will read AGENTS.md in your conversation — most coding agents (Claude Code, Cursor, Copilot) discover it automatically. It contains the full API reference in a compact format and will give your AI assistant everything it needs to write and debug AlgoChains strategies correctly without guessing.


Project structure

algochains-core/
├── docs/            full documentation
├── examples/        runnable strategy examples
├── src/algochains/  library source
├── AGENTS.md        AI coding agent reference
├── pyproject.toml
└── README.md

License

MIT — see algochains.ai for terms of service.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

algochains-1.0b4.tar.gz (246.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

algochains-1.0b4-py3-none-any.whl (261.7 kB view details)

Uploaded Python 3

File details

Details for the file algochains-1.0b4.tar.gz.

File metadata

  • Download URL: algochains-1.0b4.tar.gz
  • Upload date:
  • Size: 246.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for algochains-1.0b4.tar.gz
Algorithm Hash digest
SHA256 cdf1c884309eab18ebd427b2d47b8b0a7c78ad774ac0fc90ed5f6b9cb751b671
MD5 3c50584708b8d6e5973218d6506147d1
BLAKE2b-256 f9d40b1c68c8928a1f7bd905ca3de5299b98ea44d7fb3fdb40574049b22ad5bd

See more details on using hashes here.

File details

Details for the file algochains-1.0b4-py3-none-any.whl.

File metadata

  • Download URL: algochains-1.0b4-py3-none-any.whl
  • Upload date:
  • Size: 261.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for algochains-1.0b4-py3-none-any.whl
Algorithm Hash digest
SHA256 703086cad44d3d7cadb2fb36a230ebc8aac561468491c598c12ece8bd407516c
MD5 08159ecc53bf47809fd5bfc2c9ebe115
BLAKE2b-256 2f39aa529c65a0effdbb44318ee70baac17371d70e7dfbab69b4202c24ec6bca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page