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

replaybt demo

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.1.0.tar.gz (235.4 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.1.0-py3-none-any.whl (105.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: replaybt-1.1.0.tar.gz
  • Upload date:
  • Size: 235.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for replaybt-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d369f45f7d66fe379f92a99a85e3dfcf61d477ca88616cbed13bc3f8a0640dc6
MD5 378169552bcf35a01b9ac3312d2348f3
BLAKE2b-256 696864d940fed9995fc67be4c88adef3695afb610ecf2ff8a6d707795d1a7f56

See more details on using hashes here.

File details

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

File metadata

  • Download URL: replaybt-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 105.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for replaybt-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a5ee2a9e7caf07428faa62b9296d71206946371b80467c97998ec8d074d1b48a
MD5 1a6f7718a62fd002ff41dd8a97e99346
BLAKE2b-256 8add1c0f0c1e5b5241f53c78c73ba8a695f2a8bb160aa32807ccc5c708e9e01c

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