Skip to main content

Realistic backtesting engine for algo traders & AI agents

Project description

replaybt

Realistic backtesting engine for algo traders and AI agents.

The engine owns execution — your strategy only emits signals. No look-ahead bias by default. Gap protection, adverse slippage, and fees are built in, not bolted on.

Install

pip install replaybt

Quick Start

from replaybt import BacktestEngine, CSVProvider, Strategy, MarketOrder, Side


class EMACrossover(Strategy):
    def configure(self, config):
        self._prev_fast = self._prev_slow = None

    def on_bar(self, bar, indicators, positions):
        fast = indicators.get("ema_fast")
        slow = indicators.get("ema_slow")
        if fast is None or slow is None or self._prev_fast is None:
            self._prev_fast, self._prev_slow = fast, slow
            return None

        crossed_up = fast > slow and self._prev_fast <= self._prev_slow
        self._prev_fast, self._prev_slow = fast, slow

        if not positions and crossed_up:
            return MarketOrder(side=Side.LONG, take_profit_pct=0.05, stop_loss_pct=0.03)
        return None


engine = BacktestEngine(
    strategy=EMACrossover(),
    data=CSVProvider("ETH_1m.csv", symbol_name="ETH"),
    config={
        "initial_equity": 10_000,
        "indicators": {
            "ema_fast": {"type": "ema", "period": 15, "source": "close"},
            "ema_slow": {"type": "ema", "period": 35, "source": "close"},
        },
    },
)
results = engine.run()
print(results.summary())

Key Features

  • Signals at T, fills at T+1 — no look-ahead bias
  • Gap protection — open gaps past stops fill at the open, not the stop level
  • 11 built-in indicators with automatic multi-timeframe resampling
  • Limit orders, scale-in, breakeven stops, trailing stops, partial TP
  • Multi-asset — time-synchronized portfolio backtest
  • RL-readyStepEngine with gym-like step() / reset()
  • Declarative strategies — JSON config, no Python class needed
  • Validation — static bias auditor, delay test, OOS split
  • Optimization — parallel parameter sweep, walk-forward, Monte Carlo

Documentation

Full documentation: sirmoremoney.github.io/replaybt

License

MIT

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

replaybt-1.0.0.tar.gz (157.9 kB view details)

Uploaded Source

Built Distribution

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

replaybt-1.0.0-py3-none-any.whl (93.7 kB view details)

Uploaded Python 3

File details

Details for the file replaybt-1.0.0.tar.gz.

File metadata

  • Download URL: replaybt-1.0.0.tar.gz
  • Upload date:
  • Size: 157.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.3 cpython/3.13.2 HTTPX/0.28.1

File hashes

Hashes for replaybt-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bf888755fe6b9af28da792108f6c468bb4b68ec7a390f2bd37624b6d16b816ab
MD5 7a1eb8f00ffa6f778a679b64649f6151
BLAKE2b-256 c0f6292806d486f3e7e84902ced9b1b63aa464ddbbb215a3af7b92eac0d515f4

See more details on using hashes here.

File details

Details for the file replaybt-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: replaybt-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 93.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.3 cpython/3.13.2 HTTPX/0.28.1

File hashes

Hashes for replaybt-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a62f9f7a2ec819a2d2dc0cea3642b78b1ff3f6a05dac86689948d22c0826e6af
MD5 b9593a0e7bcb9a040f8ea677718d5488
BLAKE2b-256 2aa4a5c199ab103834a64ba2ea68680ef7ed99cd90d5c79bee42d24584fcf84e

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