Metadata-Version: 2.4
Name: replaybt
Version: 1.0.0
Summary: Realistic backtesting engine for algo traders & AI agents
Project-URL: Homepage, https://github.com/sirmoremoney/replaybt
Project-URL: Source, https://github.com/sirmoremoney/replaybt
Project-URL: Issues, https://github.com/sirmoremoney/replaybt/issues
Author: sirmoremoney
License-Expression: MIT
License-File: LICENSE
Keywords: algorithmic-trading,backtesting,crypto,trading
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Office/Business :: Financial :: Investment
Requires-Python: >=3.10
Requires-Dist: numpy>=1.24
Requires-Dist: pandas>=2.0
Provides-Extra: cli
Requires-Dist: click>=8.0; extra == 'cli'
Requires-Dist: rich>=13.0; extra == 'cli'
Provides-Extra: data
Requires-Dist: requests>=2.28; extra == 'data'
Provides-Extra: dev
Requires-Dist: matplotlib>=3.5; extra == 'dev'
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: requests>=2.28; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
Requires-Dist: mkdocs>=1.5; extra == 'docs'
Requires-Dist: pymdown-extensions>=10.0; extra == 'docs'
Provides-Extra: live
Requires-Dist: aiohttp>=3.8; extra == 'live'
Requires-Dist: websockets>=11.0; extra == 'live'
Provides-Extra: plots
Requires-Dist: matplotlib>=3.5; extra == 'plots'
Description-Content-Type: text/markdown

# 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

```bash
pip install replaybt
```

## Quick Start

```python
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-ready** — `StepEngine` 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](https://sirmoremoney.github.io/replaybt)

- [Getting Started](https://sirmoremoney.github.io/replaybt/getting-started/) — first backtest tutorial
- [Concepts](https://sirmoremoney.github.io/replaybt/concepts/) — execution loop, signal timing, gap protection
- [Cookbook](https://sirmoremoney.github.io/replaybt/cookbook/) — working recipes for common patterns
- [API Reference](https://sirmoremoney.github.io/replaybt/api/) — every class, method, and parameter

## License

MIT
