Metadata-Version: 2.4
Name: backtest-configurator
Version: 0.3.0
Summary: Backtest Configurator: a versioned, point-in-time spec for rotation strategies, and an engine that runs it on your own files. Results are hypothetical.
License-Expression: Apache-2.0
Requires-Python: <3.13,>=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: backtest-auditor==0.7.0
Requires-Dist: PyYAML==6.0.3
Requires-Dist: jsonschema==4.26.0
Requires-Dist: numpy==2.5.4
Requires-Dist: pandas==3.0.6
Requires-Dist: pyarrow==26.0.1
Provides-Extra: test
Requires-Dist: pytest==9.1.1; extra == "test"
Requires-Dist: exchange_calendars==4.13.3; extra == "test"
Requires-Dist: hypothesis==6.170.16; extra == "test"
Provides-Extra: mcp
Requires-Dist: mcp==2.3.0; extra == "mcp"
Dynamic: license-file

# Backtest Configurator

Write a rotation strategy as a short spec file, check it, confirm it, and run it on your own price files. Your AI
assistant can draft the spec from your words through the MCP server; you review every line, and nothing runs until
you confirm.

Every result this tool produces is **hypothetical**:

> Hypothetical backtest. These results were simulated with hindsight and didn't come from real trading. They don't
> reflect actual costs, slippage or market impact beyond what's stated, and hypothetical results have well-known
> limits. Past results, simulated or live, don't guarantee future results.

Not investment advice; not tailored to you; we are not a registered investment adviser or broker-dealer.

Terms of use: https://nothingbutalpha.app/terms#backtest-configurator

## What it does

- **A versioned spec (v1).** Rotation strategies only: on scheduled dates, rank and hold the top N (or all eligible
  assets), with equal, inverse-volatility or fixed weights. Adjusted prices only. A JSON Schema defines every field,
  and a fill on the same bar as the decision cannot be written.
- **Validation before anything runs.** The tool turns the spec into plain English, lists every assumption with its
  origin (your answer, filled in by the assistant, or a default), and flags values that your own text does not
  state.
- **A local engine.** It runs the spec on your own CSV or Parquet files (`date,ticker,open,high,low,close`) against a
  pinned NYSE calendar. It needs no API key and calls no data vendor.
- **A disclosure block with every output**, and a receipt with hashes of the spec, the data and every result file.
  The receipt holds no return figures.
- **A Python export.** `strategy.py` reproduces the engine's run in plain pandas and NumPy, on files the configurator accepts. The tool includes the
  Backtest Auditor's static checks, which catch some common errors and miss many.
- **Run counting.** Every run is counted in the project folder, and the count goes with every result, so you can see
  how many variants were tried before this one.

## Install

Python 3.12. The command-line tool and the MCP server need the `mcp` extra:

```
pip install "backtest-configurator[mcp]"
```

## Command-line quick start

Run these from your project folder, or pass `--project-dir`:

```
backtest-configurator validate my_strategy.yaml
backtest-configurator run my_strategy.yaml
backtest-configurator export my_strategy.yaml --out strategy.py
backtest-configurator verify .nba-configurator/results/<run>/receipt.json
backtest-configurator explain momentum
```

- `validate` reads no price data and runs nothing.
- `run` shows the rendering, the assumptions, the flags and the run count, then asks you to type `yes` at an
  interactive terminal. A plain pipe or redirect is refused, and there is no flag that skips the question.
- `verify` re-runs a logged receipt and reports whether the results reproduced. It is not a run and is not counted.

## MCP quick start

The server is `nba-configurator-mcp`, a local stdio server. Always pass the project folder: the run log and all
results live there.

Claude Code:

```
claude mcp add nba-configurator -- nba-configurator-mcp --project-dir /path/to/project
```

Claude Desktop or Cursor (`mcpServers` in the client's config file):

```json
{"mcpServers": {"nba-configurator": {"command": "nba-configurator-mcp",
                                     "args": ["--project-dir", "/path/to/project"]}}}
```

A run needs a client that supports MCP elicitation, because the server asks for confirmation through it. A client
without it gets the plain-English rendering and a refusal, and nothing runs. Then save the spec to a file and use
`backtest-configurator run` in your own terminal.

## Threat model and accepted risks

What the tool protects:

- Nothing is read or run before you confirm. Validation opens no price file and no membership file.
- Writes stay inside the project folder. A symlink, a reparse point or a file with more than one hard link is
  refused as a write target (item 1 below is the limit of that check).
- No network requests, no model calls. It never runs your code or the exported code.

What it does not protect against, accepted for this release:

1. **Races in the project folder.** A process that can write in the project folder at the same moment can swap a
   folder for a link between the path check and the open, or replace a data file between its check and its read.
   Closing this fully needs handle-relative file access.
2. **The confirmation records a channel, not a person.** A program that runs the command-line tool inside a
   pseudo-terminal can answer the prompt, and an MCP client that accepts elicitation requests automatically can
   confirm without showing the request. The receipt records the channel (`cli_prompt`, `mcp_elicitation`), never
   "user confirmed".
3. **Reads may be anywhere your account can read.** Once you confirm, a data path may point outside the project
   folder. That is by design: the files are yours.
4. **Run counts are per project folder.** A new folder starts a new count.
5. **The `mcp` extra installs server packages the tool never uses** (an HTTP server and its dependencies). They are
   pinned, but an advisory on any of them concerns this package too.
6. **The wheel is not byte-reproducible.** Only files built and tested in CI are published, with PyPI attestations.
7. **No hash-locked install from PyPI.** Direct dependencies are pinned exactly; transitive ones are not.
8. **Developer regeneration commands ship in the package.** `python -m nba_configurator.schema_source --write` and
   `python -m nba_configurator.nyse_calendar --write` rewrite the installed schema and calendar with the same
   generated content.

## License

Apache-2.0.
