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.0b2.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.0b2-py3-none-any.whl (55.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: algochains-1.0b2.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.0b2.tar.gz
Algorithm Hash digest
SHA256 6fd26b1d3bb1fee854f71e4da780b9d64a1fd4e17b88cb90328db6313eb16505
MD5 01ea9256ca7ea7dd7bc10ffc4082f64f
BLAKE2b-256 58a9cbacd86368f65f90ccea22bc1b48c40d1aeb3f61bcccce6ed32f24cd0ba9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: algochains-1.0b2-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.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 8f377d8ec1976ea74d0d497378e868674c114fe510b767fbea5e6dc6c161c7b3
MD5 d13e9f112426b10f9966025a7ead9064
BLAKE2b-256 7fa92c3c58255fb57d0c9dfc2a62a3f8314e8f2ff1f02c9450a6e6096f92d97b

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