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 -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ 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 user_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)

user_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 user_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 llms.txt before we start working."

Your agent will read llms.txt in your conversation. 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
├── llms.txt         AI assistant 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.0b1.tar.gz (44.1 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.0b1-py3-none-any.whl (55.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for algochains-1.0b1.tar.gz
Algorithm Hash digest
SHA256 f2fa7155b6d26dcb3099e0fa0e5a080e462a7389cc605b204ab228e6df892200
MD5 6cb3c207e56aa0e0ca6093c8cbe148b6
BLAKE2b-256 c0a7c1694d0f6202eb53ba137b0de1d310dd482bce3dff82cef4c436fdcb6718

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for algochains-1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 ca30afa02016632f9bd3b4bb042ad068470a5228c6fb909ec86715e9a1ce8715
MD5 905527de645d5a6114f077318ca1b725
BLAKE2b-256 9b69a65d3e8ed5247509b79aa66de1a3e7f6bc2f9cd7838750b4163bbbf94c1d

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