Backtests with costs, a held-out test that counts once, a score that counts every version tried.
Maintain this server? Claim it
Call this server's tools from your browser. Nothing to install.
Bearer followed by your QuantWright API key (app: API keys).
Requests go through mcptry because browsers can't call most MCP servers directly. Header values are sent to the server for that request only and are never stored or logged.
Tool list from our last check. Connect live to refresh it.
Checks a trader's own trades against a run's rule, on the price history this server holds: for each trade, in their order, whether the rule would have taken it and, if not, why (already in a trade, no entry signal that day, no bar that day). Use it when the trader lists trades they made and asks which the rule took, instead of working it out by hand. Takes a run (run_id) and the trades, each {side, entry, exit?}; answers in words, never prices. It re-runs the run's code, so it counts as a run on the run's symbol.
The trader's own trades, in their order, each stamp exactly as the trader wrote it.
A run_id run_backtest or run_held_out_test returned: the run whose code is checked against the trades.
A study's id; with `version`, one of its runs.
The clock the trader says their times are on ("UTC+2", "New York", "Europe/Prague"). Left out: the clock the run's trade list is on (ET for stocks and ETFs, UTC otherwise).
This tool isn't marked read-only, so it may change something on the server or in an account you connected.
Checks a trader's own trades against a run's rule, on the price history this server holds: for each trade, in their order, whether the rule would have taken it and, if not, why (already in a trade, no entry signal that day, no bar that day). Use it when the trader lists trades they made and asks which the rule took, instead of working it out by hand. Takes a run (run_id) and the trades, each {side, entry, exit?}; answers in words, never prices. It re-runs the run's code, so it counts as a run on the run's symbol.
| Argument | Type | Description |
|---|---|---|
| run_id | string | A run_id run_backtest or run_held_out_test returned: the run whose code is checked against the trades. |
| trades* | array | The trader's own trades, in their order, each stamp exactly as the trader wrote it. |
| version | any | |
| study_id | string | A study's id; with `version`, one of its runs. |
| time_zone | string | The clock the trader says their times are on ("UTC+2", "New York", "Europe/Prague"). Left out: the clock the run's trade list is on (ET for stocks and ETFs, UTC otherwise). |
{
"type": "object",
"required": [
"trades"
],
"properties": {
"run_id": {
"type": "string",
"description": "A run_id run_backtest or run_held_out_test returned: the run whose code is checked against the trades."
},
"trades": {
"type": "array",
"items": {
"type": "object",
"required": [
"side",
"entry"
],
"properties": {
"exit": {
"type": "string",
"description": "When they exited, the same way. Left out when they gave none."
},
"side": {
"enum": [
"long",
"short"
],
"type": "string"
},
"entry": {
"type": "string",
"description": "When they entered: \"YYYY-MM-DD\", or \"YYYY-MM-DD HH:MM\" on the clock they wrote."
}
},
"additionalProperties": false
},
"maxItems": 50,
"minItems": 1,
"description": "The trader's own trades, in their order, each stamp exactly as the trader wrote it."
},
"version": {
"anyOf": [
{
"type": "integer",
"minimum": 1
},
{
"type": "string",
"pattern": "^[vV]?\\d+$"
}
]
},
"study_id": {
"type": "string",
"description": "A study's id; with `version`, one of its runs."
},
"time_zone": {
"type": "string",
"description": "The clock the trader says their times are on (\"UTC+2\", \"New York\", \"Europe/Prague\"). Left out: the clock the run's trade list is on (ET for stocks and ETFs, UTC otherwise)."
}
},
"additionalProperties": false
}Opens a study, the named set of runs every backtest belongs to: call it once per question, before run_backtest. Can set a hold-out period, once and only here, that no run tests except run_held_out_test.
| Argument | Type | Description |
|---|---|---|
| name* | string | What the study tests, in a few words. |
| hold_out | object | The days kept back from every run but run_held_out_test; set once, here. |
{
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"type": "string",
"description": "What the study tests, in a few words."
},
"hold_out": {
"type": "object",
"required": [
"from"
],
"properties": {
"to": {
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"description": "A day, YYYY-MM-DD."
},
"from": {
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"description": "A day, YYYY-MM-DD."
}
},
"description": "The days kept back from every run but run_held_out_test; set once, here.",
"additionalProperties": false
}
},
"additionalProperties": false
}Start here to backtest a trading idea. This server holds the price history (US stocks and ETFs, spot crypto, FX, spot gold and silver; daily and intraday bars) and runs backtests on it, so no price data needs to be downloaded or found on the web. Returns the markets and bar sizes served, the rules every run is held to, and how to write the strategy code; then call create_study.
No arguments.
{
"type": "object",
"required": [],
"properties": {},
"additionalProperties": false
}Reads a backtest result by its run_id (when run_backtest answered "running", call this until the run ends), or a study's runs by study_id (one of them with version). A run comes with its trades, a page at a time (trades_page).
| Argument | Type | Description |
|---|---|---|
| run_id | string | A run_id run_backtest or run_held_out_test returned. |
| version | any | |
| study_id | string | A study's id, for its runs (the newest 20 by default); with `version`, one of them. |
| trades_page | integer | With a run (run_id, or study_id with version): the page of its trade list, from 1; a page holds 100 trades. Left out: the first. |
| before_version | any | With study_id: the 20 runs before this version (a list's `next` gives it). |
{
"type": "object",
"required": [],
"properties": {
"run_id": {
"type": "string",
"description": "A run_id run_backtest or run_held_out_test returned."
},
"version": {
"anyOf": [
{
"type": "integer",
"minimum": 1
},
{
"type": "string",
"pattern": "^[vV]?\\d+$"
}
]
},
"study_id": {
"type": "string",
"description": "A study's id, for its runs (the newest 20 by default); with `version`, one of them."
},
"trades_page": {
"type": "integer",
"minimum": 1,
"description": "With a run (run_id, or study_id with version): the page of its trade list, from 1; a page holds 100 trades. Left out: the first."
},
"before_version": {
"anyOf": [
{
"type": "integer",
"minimum": 1
},
{
"type": "string",
"pattern": "^[vV]?\\d+$"
}
],
"description": "With study_id: the 20 runs before this version (a list's `next` gives it)."
}
},
"additionalProperties": false
}Backtests a trading rule on this server's price history: one backtesting.py Strategy class, one symbol, one bar size, in a study. Use it to test, backtest or evaluate a trading rule or strategy, instead of downloading prices or searching the web for results. Returns summary figures (return, drawdown, Sharpe, win rate, trades, a grade, whether it beat buy-and-hold) and the run's trades (when each entered and left, which exit ended it, its side, win or loss), never prices or bars; a figure may be withheld, with the reason. Waits up to 90 s, then answers status "running" with a run_id for get_result.
| Argument | Type | Description |
|---|---|---|
| code* | string | One backtesting.py Strategy class (describe_data has the rules). |
| costs | any | The costs: two fractions of the trade value, or a list of costs each in its own unit. |
| label | string | A short text shown with the run. |
| symbol* | string | One ticker ("QQQ", "BTCUSD", "EURUSD"). |
| window | any | Dates ({from, to}; `to` may be "latest") or the last N days, months or years ({last: {n, unit}}). Left out: the standard history, the newest bars counted back from the newest bar, cut at the start of the hold-out. |
| study_id* | string | The id create_study returned. |
| timeframe |
The final out-of-sample check: runs a finished run's exact code once over its study's hold-out period. Call it at the end, on the run you would keep: the first held-out test per account and market is the one that counts, and a hold-out with too few trades for figures (a result needs 10) spends it all the same: each development run says how many trades the hold-out is expected to hold, in `hold_out_estimate`.
| Argument | Type | Description |
|---|---|---|
| run_id* | string | A run of a study with a hold-out, which ran. |
{
"type": "object",
"required": [
"run_id"
],
"properties": {
"run_id": {
"type": "string",
"description": "A run of a study with a hold-out, which ran."
}
},
"additionalProperties": false
}| string |
| account_usd | number | The starting account, in US dollars. |
| stated_rules | array | Rules the trades are checked against, one per kind. |
{
"type": "object",
"required": [
"study_id",
"code",
"symbol",
"timeframe"
],
"properties": {
"code": {
"type": "string",
"maxLength": 50000,
"description": "One backtesting.py Strategy class (describe_data has the rules)."
},
"costs": {
"oneOf": [
{
"type": "object",
"required": [],
"properties": {
"slippage": {
"type": "number",
"maximum": 0.05,
"minimum": 0,
"description": "A fraction of the trade value per fill (entry and exit)."
},
"commission": {
"type": "number",
"maximum": 0.05,
"minimum": 0,
"description": "A fraction of the trade value at entry (0.0005 is 0.05%), charged once per round trip."
}
},
"additionalProperties": false
},
{
"type": "array",
"items": {
"type": "object",
"required": [
"side",
"amount",
"unit",
"basis"
],
"properties": {
"side": {
"enum": [
"commission",
"slippage",
"spread"
],
"type": "string"
},
"unit": {
"enum": [
"percent",
"bps",
"usd_per_share",
"usd_per_ounce",
"pips",
"usd_per_order"
],
"type": "string",
"description": "usd_per_share on stocks and ETFs; usd_per_ounce on spot gold and silver; pips on currency pairs; percent, bps and usd_per_order (a flat fee per order) on any market."
},
"basis": {
"enum": [
"per_side",
"round_trip"
],
"type": "string",
"description": "per_side: on each fill; round_trip: once for the entry and exit together."
},
"amount": {
"type": "number",
"minimum": 0,
"description": "The figure in `unit` (0.005 usd_per_share is half a cent a share; 0.1 percent is 0.1%)."
}
},
"additionalProperties": false
},
"maxItems": 6,
"minItems": 1
}
],
"description": "The costs: two fractions of the trade value, or a list of costs each in its own unit."
},
"label": {
"type": "string",
"description": "A short text shown with the run."
},
"symbol": {
"type": "string",
"description": "One ticker (\"QQQ\", \"BTCUSD\", \"EURUSD\")."
},
"window": {
"oneOf": [
{
"type": "object",
"required": [],
"properties": {
"to": {
"anyOf": [
{
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"description": "A day, YYYY-MM-DD."
},
{
"type": "string",
"const": "latest"
}
]
},
"from": {
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$",
"description": "A day, YYYY-MM-DD."
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"last"
],
"properties": {
"last": {
"type": "object",
"required": [
"n",
"unit"
],
"properties": {
"n": {
"type": "integer",
"minimum": 1
},
"unit": {
"enum": [
"days",
"months",
"years"
],
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
],
"description": "Dates ({from, to}; `to` may be \"latest\") or the last N days, months or years ({last: {n, unit}}). Left out: the standard history, the newest bars counted back from the newest bar, cut at the start of the hold-out."
},
"study_id": {
"type": "string",
"description": "The id create_study returned."
},
"timeframe": {
"enum": [
"1m",
"5m",
"15m",
"30m",
"1h",
"4h",
"1d"
],
"type": "string"
},
"account_usd": {
"type": "number",
"description": "The starting account, in US dollars."
},
"stated_rules": {
"type": "array",
"items": {
"oneOf": [
{
"type": "object",
"required": [
"kind"
],
"properties": {
"kind": {
"type": "string",
"const": "no_overnight"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"kind",
"time"
],
"properties": {
"tz": {
"type": "string",
"description": "An IANA time zone (\"America/New_York\"); none is New York."
},
"kind": {
"type": "string",
"const": "flat_by"
},
"time": {
"type": "string",
"pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
"description": "\"HH:MM\", 24-hour."
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"kind",
"from",
"to"
],
"properties": {
"to": {
"type": "string",
"pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
"description": "\"HH:MM\", 24-hour."
},
"tz": {
"type": "string",
"description": "An IANA time zone (\"America/New_York\"); none is New York."
},
"from": {
"type": "string",
"pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
"description": "\"HH:MM\", 24-hour."
},
"kind": {
"type": "string",
"const": "session"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"kind",
"n"
],
"properties": {
"n": {
"type": "integer",
"maximum": 10,
"minimum": 1
},
"kind": {
"type": "string",
"const": "max_trades_per_day"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"kind",
"pct"
],
"properties": {
"pct": {
"type": "number",
"maximum": 10,
"description": "A percent as written: 0.5 is 0.5%.",
"exclusiveMinimum": 0
},
"kind": {
"type": "string",
"const": "risk_per_trade_pct"
}
},
"additionalProperties": false
}
]
},
"maxItems": 5,
"description": "Rules the trades are checked against, one per kind."
}
},
"additionalProperties": false
}