Metadata-Version: 2.4
Name: statera
Version: 1.0.0
Summary: Research, validation and simulated (paper/replay) execution framework for rule-based crypto spot strategies
Author: ccakirr
License-Expression: MIT
Project-URL: Homepage, https://github.com/ccakirr/statera
Project-URL: Repository, https://github.com/ccakirr/statera
Project-URL: Issues, https://github.com/ccakirr/statera/issues
Keywords: quantitative-finance,backtesting,walk-forward,monte-carlo,paper-trading,crypto
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Office/Business :: Financial :: Investment
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy<3,>=2.5.5
Requires-Dist: pandas<4,>=3.1.1
Requires-Dist: ccxt<5,>=4.5.94
Requires-Dist: optuna<6,>=5.1.0
Requires-Dist: matplotlib<4,>=3.11.2
Requires-Dist: PyYAML<7,>=6.0.4
Provides-Extra: dev
Requires-Dist: pytest<10,>=9.2.0; extra == "dev"
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: twine>=6.1; extra == "dev"
Dynamic: license-file

# Statera

**English** · [Türkçe](https://github.com/ccakirr/statera/blob/main/README.tr.md)

Statera is a Python framework for **researching, validating and paper-trading rule-based crypto spot strategies**
(long-only, no leverage). It answers one question with auditable evidence: *does this strategy show a robust,
cost-adjusted edge on data it was never tuned on?* "No" is a normal, valid answer.

Statera is **not a profitable trading bot** and places **no real-money orders**. `APPROVED_FOR_PAPER` authorises
simulated execution only. Passing validation does not prove future profitability.

## Who it is for
- Quant developers who want a realistic backtester plus walk-forward, holdout, stress and Monte Carlo risk checks.
- Application developers embedding strategy evaluation in their own products (Python API, CLI, structured results).
- Teams that need reproducible, fail-closed research records rather than optimistic equity curves.

## What problems it solves
| Problem | Statera's answer |
|---|---|
| Backtests that ignore fees, slippage, gaps, cash limits and exchange minimums | One shared engine with next-bar fills, conservative intrabar ordering and exchange precision |
| Overfitting through unlimited parameter search | Bounded global trial budget; every attempted configuration is recorded |
| Holdout data silently reused until something passes | Untouched chronological holdout, tested once per frozen config; inspections recorded across runs |
| Position sizing chosen from optimistic curves | Monte Carlo sizing on development data only, with hard user risk limits |
| Backtest/live rule drift | Backtest, replay and paper trading share the same engine |

## Key capabilities
- Public Binance OHLCV via CCXT (no API keys), local cache, validation; gaps reported, never forward-filled.
- Python strategy plugins with explicit, bounded parameter spaces; register in-process, by directory or entry point.
- Realistic engine: next-bar open entries, fees and slippage on every fill, gap fills, stop-first on ambiguous bars,
  cash and quantity constraints, net R = net PnL / initial monetary risk, marked-to-market drawdown.
- Research pipeline: grid/Optuna search → purged walk-forward → sensitivity, cost and delay stress → Monte Carlo
  risk sizing → freeze → single holdout test → `APPROVED_FOR_PAPER` / `REJECTED` / `INSUFFICIENT_DATA`.
- Versioned, hashed, expiring trading plans; replay and paper trading with SQLite persistence, duplicate-order
  prevention, restart recovery and kill switches.

## Architecture (high level)
```mermaid
flowchart LR
  D[data: CCXT / your OHLCV] --> S[strategy plugin: signals]
  S --> E[engine: fills, costs, sizing, MTM]
  E --> P[pipeline: optimise, walk-forward, gates]
  P --> R[risk: Monte Carlo sizing]
  R --> H[single holdout test]
  H --> A[approval]
  A --> PL[trading_plan.json]
  PL --> T[trader: replay / paper]
  T --> E
```
See the [architecture guide](https://github.com/ccakirr/statera/blob/main/docs/en/architecture.md).

## Installation
Requires Python 3.12 or later. Use `import statera` in Python and `statera` at the command line.

Install from PyPI once the first release is published.

```bash
python -m pip install statera
```

Install from Git once the desired revision is pushed. Replace `REF` with a tag or commit.

```bash
python -m pip install "git+https://github.com/ccakirr/statera.git@REF"
```

For a TestPyPI release, use a fresh virtual environment in a checkout of the matching version. Install
the pinned dependencies from PyPI, then install the Statera wheel from TestPyPI.

```bash
python -m pip install --index-url https://pypi.org/simple/ -r requirements.txt
python -m pip install --index-url https://test.pypi.org/simple/ --no-deps --only-binary=:all: "statera==1.0.0"
python -m pip check
```

For local development and distribution builds, run the following from a checkout.

```bash
python -m pip install -e ".[dev]"
python -m build
python -m twine check --strict dist/*
```

Use `python -m pip install -r requirements-lock.txt` for the full verified dependency set.

### Publishing

Configure a pending GitHub Actions Trusted Publisher on each index before the first upload. Set the
project to `statera`, enter the actual GitHub repository owner and name, and set the workflow
filename to `publish.yml`. Use the GitHub environment `pypi` for PyPI and `testpypi` for TestPyPI.
See [PyPI's Trusted Publishing setup guide](https://docs.pypi.org/trusted-publishers/creating-a-project-through-oidc/).

To publish to TestPyPI, run **Publish Python distribution** manually from GitHub Actions on the branch
or tag you want to test. To publish to PyPI, push a version tag such as `v1.0.0` or publish a GitHub
Release for that tag. Match the tag to the version in `pyproject.toml` and `statera.__version__`.

## Quick start
CLI (installed as `statera`; `python main.py` also works in a checkout):
```bash
statera data                                       # download/validate BTC/USDT, ETH/USDT 15m (~2 years)
statera backtest --strategy ema_crossover --offline
statera research --strategy ema_crossover --offline
statera report
```
Python:
```python
import statera

cfg = statera.load_config(base_dir="./my_statera")      # state, data, reports live under this directory
bt = statera.backtest("ema_crossover", cfg=cfg, symbol="BTC/USDT", timeframe="15m", offline=True)
print(bt.metrics["expectancy_R"], bt.equity_metrics["max_drawdown"])

res = statera.research("ema_crossover", cfg=cfg, offline=True)
print(res.decision, res.reasons[:3])                # APPROVED_FOR_PAPER | REJECTED | INSUFFICIENT_DATA
```
(`offline=True` needs a cache in that `base_dir`; run `statera --base-dir ./my_statera data` first or omit it.)

## Documentation
| Topic | English | Türkçe |
|---|---|---|
| Getting started | [getting-started](https://github.com/ccakirr/statera/blob/main/docs/en/getting-started.md) | [başlangıç](https://github.com/ccakirr/statera/blob/main/docs/tr/getting-started.md) |
| Architecture | [architecture](https://github.com/ccakirr/statera/blob/main/docs/en/architecture.md) | [mimari](https://github.com/ccakirr/statera/blob/main/docs/tr/architecture.md) |
| Configuration | [configuration](https://github.com/ccakirr/statera/blob/main/docs/en/configuration.md) | [yapılandırma](https://github.com/ccakirr/statera/blob/main/docs/tr/configuration.md) |
| Strategy development | [strategy-development](https://github.com/ccakirr/statera/blob/main/docs/en/strategy-development.md) | [strateji geliştirme](https://github.com/ccakirr/statera/blob/main/docs/tr/strategy-development.md) |
| Research & optimisation | [research-and-optimization](https://github.com/ccakirr/statera/blob/main/docs/en/research-and-optimization.md) | [araştırma ve optimizasyon](https://github.com/ccakirr/statera/blob/main/docs/tr/research-and-optimization.md) |
| Risk management | [risk-management](https://github.com/ccakirr/statera/blob/main/docs/en/risk-management.md) | [risk yönetimi](https://github.com/ccakirr/statera/blob/main/docs/tr/risk-management.md) |
| Execution | [execution](https://github.com/ccakirr/statera/blob/main/docs/en/execution.md) | [yürütme](https://github.com/ccakirr/statera/blob/main/docs/tr/execution.md) |
| Python API reference | [python-api](https://github.com/ccakirr/statera/blob/main/docs/en/python-api.md) | [Python API](https://github.com/ccakirr/statera/blob/main/docs/tr/python-api.md) |
| Integrations | [integrations](https://github.com/ccakirr/statera/blob/main/docs/en/integrations.md) | [entegrasyonlar](https://github.com/ccakirr/statera/blob/main/docs/tr/integrations.md) |
| Limitations | [limitations](https://github.com/ccakirr/statera/blob/main/docs/en/limitations.md) | [sınırlamalar](https://github.com/ccakirr/statera/blob/main/docs/tr/limitations.md) |

See the [runnable integration examples](https://github.com/ccakirr/statera/blob/main/examples/README.md).

## Maturity
Version 1.0.0 is the initial beta release. An automated test suite and one real end-to-end research run
verify this single-developer project. The supported Python API is listed in `statera.__all__`.

## Verified results (2026-11-29)
- Test suite: `pytest` → **83 passed** (deterministic synthetic fixtures; see [getting started](https://github.com/ccakirr/statera/blob/main/docs/en/getting-started.md)).
- Real research run `20261129T104233Z_018709` (`ema_crossover`, BTC/USDT and ETH/USDT 15m, 70,080 bars each,
  2024-11-29 → 2026-11-29, 0 missing bars): **REJECTED**. 60/60 optimisation trials had negative development
  expectancy (best E[R]: BTC −0.062, ETH −0.086); walk-forward out-of-sample E[R]: BTC −0.120 (161 trades),
  ETH −0.218 (373 trades). The top 3 candidates failed every development gate; the holdout (from 2026-07-06)
  was never inspected and no plan was approved. See the [reference run reports](https://github.com/ccakirr/statera/blob/main/docs/reference-run/README.md).

## Limitations
Bar-level simulation (unknown intrabar path, no order book or partial fills), single long-only spot position, no
live trading, statistical limits of walk-forward selection and bootstrap resampling. See the
[full list of limitations](https://github.com/ccakirr/statera/blob/main/docs/en/limitations.md).

## License
Statera is distributed under the [MIT License](https://github.com/ccakirr/statera/blob/main/LICENSE).
