# Backtest Audit

> Audit a backtest log. stats.py measures it, stress.py adds costs, splits, reshuffles and drops the best trades, flags.py exits 1 on too few trades, profit on few trades, a win rate that collapses out of sample or costs that turn it negative. It measures a log, recommends no trade, predicts nothing.

Backtest Audit is a paid AI agent skill on Agensi by Hale Sinclair, in Trading & Investing. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $9.99 (one-time purchase)
- Creator: [Hale Sinclair](https://www.agensi.io/creators/hale-sinclair)
- Category: [Trading & Investing](https://www.agensi.io/skills/trading-investing)
- Version: 1.0
- Last updated: 2026-12-01
- Security: scan passed (2026-12-01); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/backtest-audit
- Tags: trading, finance, database, backtest, trade-log, equity-curve, drawdown, expectancy

## About this skill

### The problem
A backtest ends in one flattering number. Behind it there may be 20 trades, three lucky ones carrying the profit, a second half that looks nothing like the first, or a result that disappears once costs are paid. Nobody redoes that arithmetic by hand.

### What it does
Your agent reads the log and reports; three standard-library Python scripts do the arithmetic:
- **stats.py**: number of trades, win rate, average win and loss, expectancy per trade, profit factor, largest drawdown and how many trades it lasted, exposure, longest losing run.
- **stress.py**: the result after a cost and a slippage per trade (your flags), first half against second half or against a split date, the trades reshuffled 1,000 times with a fixed seed (the range of the largest drawdown), and the result with the best five trades removed.
- **flags.py**: four flags, exit 1 if any: too few trades for claims, profit resting on few trades, a win rate that falls apart out of sample, costs that turn the result negative.

It reads a CSV trade log (`date,side,quantity,price,profit`), a TradingView-style strategy export (Entry and Exit rows; a trade still open is left out and said) or an equity curve, finding the layout from the header; columns can be mapped with flags. Numbers may be written 1,234.50, 1.234,50, 1 234,50, 1'234.50, (12.5), -$3.50, 3-, 12.50 USD or 6.9e-05; the decimal mark is read from the column or named with `--decimal`, and a file it cannot read is refused by name, with every skipped row counted and its reason. Each script is one file that needs no other file. No model call, no network, no market data; it changes no file of your project and writes only the `--out` file you name.

**It measures a log. It recommends no trade and predicts nothing.**

### What the check run proves
- **Four synthetic logs of different shape** (all declared synthetic, seeded): a plain 240-trade log, a 36-trade log built to raise flags, a TradingView-style export of 80 trades and an equity curve. Trades, total, wins, expectancy, drawdown, longest losing run, the best-five-removed result and the after-cost total equal an independent count (awk) on the plain log.
- **Both directions**: the lucky log raises the concentration and the out-of-sample flags (exit 1); the steady log, whose second half is better, raises none (exit 0); too few trades and costs that turn a profit negative are flagged.
- **Faults handled**: a missing, locked or non-UTF-8 file is one line or one note, never a traceback; a column flag naming no column lists the columns; a header with no row, rows with no number, one trade, all wins and all losses do not crash; `--out` aimed at the log by 7 routes is refused; the reshuffle is the same on every run. Each guard is shown failing on a deliberately broken copy.
- **Files from other projects** (reduced, with their sources in inputs/SOURCES.md): an equity curve and a returns file with an exponent value give trades, wins and total equal to awk's; a TradingView-header file with only `Net P&L %` is refused in one line and read with `--profit-col`.
- Number formats, open trades, newest-first logs, empty and one-result logs, and `--out` aimed at the log are covered by 108 cases, each failing on the previous version of the scripts (checks/demo-round2.out).
- The TradingView-style file is our imitation of the layout, not a file exported by TradingView: no real TradingView export has been seen.

### How it works
1. Save the log as CSV.
2. stats.py measures, stress.py stresses (ask what costs and slippage are; none are assumed), flags.py flags.
3. The agent reports figures, flags and what was not tested, and never says a strategy works.
Everything runs locally on Python 3.9+ standard library.

### Use cases
- Check a backtest before trusting its headline number.
- See what costs and slippage do to the result.
- Find whether a few lucky trades carry the profit.
- Compare the first half of a log with the second, or before and after a date.

### Known limitations
- No check for look-ahead bias, survivorship or fitting to the data.
- The reshuffle assumes independent trades; real drawdowns can be worse.
- Exposure does not merge overlapping trades.
- One unit, no currency conversion or position sizing. Money prints with 2 decimals, so a log of tiny fractions shows rounded figures. A `%` is dropped and said: the number before it is read as written.
- No real TradingView export has been seen: the two TradingView-header files tested are another project's engine fixtures, and a real export with other headers may need `--profit-col`.
- stress.py takes about 35 seconds per 100,000 trades on the author's machine (72 s on 200,000, measured); above 20,000 trades it says so on stderr first.
- The out-of-sample flag cuts one log in two; it is not walk-forward testing.

## Requires

- Python

No accounts, API keys or services. Python 3.9+ on the machine.

## Known limitations

Measures a log: recommends no trade, predicts nothing, and passing every flag proves nothing about the future. Four test logs are synthetic; the TradingView-style file imitates the layout and no real TradingView export has been seen, so a real export with different headers may need --profit-col. Two reduced files from other projects were also read. Thresholds are rules of thumb, not statistical tests. Nobody has run it on a live strategy.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Backtest Audit skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### Does it tell me whether to trade this strategy?

No. It measures the log and raises flags; it recommends no trade and predicts nothing.

### Which files can it read?

CSV trade logs (date,side,quantity,price,profit), TradingView strategy exports (Entry and Exit rows) and equity curves; columns can be mapped with --date-col, --profit-col, --equity-col, and the decimal mark with --decimal point|comma.

### Does it know my costs?

No. You give --cost and --slippage; with none given the costs flag is not tested and says so.

### Does it need market data or the internet?

No. It reads only the log you name and makes no network calls.

### Does it change my files?

No. It writes only the --out file you name and refuses to overwrite the log.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
