Metadata-Version: 2.4
Name: reamer-research
Version: 4.11.5
Summary: Python and C++ backtesting and live trading engine with visual trade diagnostics
Author: Reamer Labs
Keywords: backtesting,algorithmic trading,trading,quant,backtest,live trading,futures,forex
License-Expression: LicenseRef-Reamer-Research
License-File: LICENSE.txt
Project-URL: Homepage, https://reamerlabs.com
Project-URL: Documentation, https://reamerlabs.com/docs
Project-URL: Pricing, https://reamerlabs.com/pricing
Project-URL: Examples, https://github.com/reamerlabs/reamer-research-examples
Project-URL: Issues, https://github.com/reamerlabs/reamer-research/issues
Project-URL: Changelog, https://reamerlabs.com/docs/research-changelog
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Office/Business :: Financial :: Investment
Requires-Python: >=3.9
Requires-Dist: numpy>=1.21
Provides-Extra: pandas
Requires-Dist: pandas>=1.3; extra == "pandas"
Description-Content-Type: text/markdown

# Reamer Research

Reamer Research is a Python and C++ backtesting and live trading engine for strategies on bars of any type. You write `on_bar` in plain Python with numpy, the compiled engine fills its orders under a public [execution specification](https://reamerlabs.com/docs/execution-spec), and the visual trade diagnostics tool charts every closed trade on its bars, with the values you printed beside it.

- **Fast compiled engine**, prebuilt inside this package: nothing to compile.
- **Fills you can read**: a seeded tick path inside each bar, with slippage, spread, commission, margin, overnight swap and futures rolls. A fixed `rng_seed` gives the same result byte for byte.
- **Visual trade diagnostics**: `open_viewer=True` opens the run in your browser, one chart per trade, with your printed indicator values, console lines and a Monte Carlo simulation.
- **Orders a real venue takes**: market, limit and stop orders, take-profit and stop-loss brackets, partial closes, IOC and GTD, modify and cancel.
- **Many tickers on one wall clock**, so rows never need to line up, and memory-mapped `.bin` files for data larger than RAM.
- **Live trading**: `rr.Relay` sends the same orders a backtest returns to your own broker connection.

## Install

```bash
pip install reamer-research            # numpy is the only dependency
pip install "reamer-research[pandas]"  # to pass DataFrames and get trades as one
```

Linux x86_64 (glibc 2.35 or later, such as Ubuntu 22.04+), macOS on Apple Silicon (11 or later), and Windows through WSL2. Python 3.9 or later.

## A first backtest

```bash
curl -LO https://raw.githubusercontent.com/reamerlabs/reamer-research-examples/main/python/sample_data/AAPL.csv
```

```python
import numpy as np
import reamer_research as rr

def on_bar(d):
    c, h, l = d.close, d.high[1:], d.low[1:]
    if c[0] == 0: return               # warm-up: the window is still filling
    atr = (np.maximum(h, c[:-1]) - np.minimum(l, c[:-1])).mean()
    mid, px = c.mean(), c[-1]
    if d.position() == 0 and px < mid - 2 * atr:
        return rr.buy_market(10, take_profit=mid, stop_loss=px - 2 * atr)
    if d.position() == 0 and px > mid + 2 * atr:
        return rr.sell_market(10, take_profit=mid, stop_loss=px + 2 * atr)

print(rr.backtest(on_bar, 'AAPL.csv', lookback=20, open_viewer=True))
```

That is an ATR band reversion: it fades a close more than two ATRs from its 20-bar mean, with a bracket that targets the mean. It prints the summary and opens the run in the visual trade diagnostics tool. `AAPL.csv` is synthetic sample data; any CSV of bars with a header row works, and `rr.backtest` also takes pandas DataFrames, numpy arrays and `.bin` files.

## Function, class or object

```python
rr.backtest(on_bar, 'AAPL.csv', lookback=20)     # a function on_bar(data)
rr.backtest(AtrBands, 'AAPL.csv')                # a class with on_bar, instantiated once
rr.backtest(AtrBands(k=2.5), 'AAPL.csv')         # an object with on_bar, configured by you
```

```python
class AtrBands:
    lookback = 20                      # bars per window

    def __init__(self, k=2.0, qty=10):
        self.k, self.qty = k, qty      # settings
        self.entries = 0               # state kept across bars

    def on_bar(self, d):
        c, h, l = d.close, d.high[1:], d.low[1:]
        if c[0] == 0: return
        atr = (np.maximum(h, c[:-1]) - np.minimum(l, c[:-1])).mean()
        mid, px, band = c.mean(), c[-1], self.k * atr
        if d.position() == 0 and px < mid - band:
            self.entries += 1
            return rr.buy_market(self.qty, take_profit=mid, stop_loss=px - band)
        if d.position() == 0 and px > mid + band:
            self.entries += 1
            return rr.sell_market(self.qty, take_profit=mid, stop_loss=px + band)
```

## Costs and results

```python
result = rr.backtest(AtrBands, 'AAPL.csv', commission_per_unit=0.005, spread=0.01, slippage=0.01)
result.net_pnl, result.sharpe_ratio, result.equity_drawdown_relative
result.trades_frame()                  # every round trip as a DataFrame (the pandas extra)
result.monte_carlo(simulations=10000)  # resampled per-trade returns
result.write_json('run.json')          # every fill, the order log, the equity curve
```

## Evaluation Mode and licences

This package runs in Evaluation Mode with no key or sign-up: one ticker per backtest, up to 30 days of bar time or 50,000 bars, and no live trading. A run past a limit raises `rr.EvaluationLimit`, naming the limit. A [Reamer Research licence](https://reamerlabs.com/pricing) is $20 a month and removes every limit; you activate it once per machine with `reamer-license` from the [full kit](https://reamerlabs.com/download), and the same code runs unchanged.

The full kit adds the C++ wrapper, the C ABI, market-data fetchers for Alpaca and Databento, a paper broker and relay receiver for going live, strategy templates and the reference documents.

## Links

- [Documentation](https://reamerlabs.com/docs): [Python quickstart](https://reamerlabs.com/docs/research-quickstart), [execution specification](https://reamerlabs.com/docs/execution-spec), [going live](https://reamerlabs.com/docs/research-live)
- [Example strategies and data scripts](https://github.com/reamerlabs/reamer-research-examples), MIT License
- [Pricing](https://reamerlabs.com/pricing) and [the full kit](https://reamerlabs.com/download)
- [Questions and bug reports](https://github.com/reamerlabs/reamer-research/issues)

Reamer Research is proprietary software by Reamer Labs, under the licence in this package's `.dist-info/licenses/LICENSE.txt`. The Python package source inside it is Wrapper Code you may read, change and keep in your own tree (Section 4).
