# x402stock Backtest API

> x402stock Backtest API is a paid API for AI agents from x402stock.xyz, paid per call via x402, $0.5/call, status unknown (last checked 2026-10-22).

Runs a historical backtest of SMA crossover or RSI reversion trading strategies on a given stock ticker, returning performance metrics, trade list, and a chart artifact

## Facts

- Endpoint: GET https://x402stock.xyz/api/v1/backtest/%7Bticker%7D?utm_source=zero.xyz
- Price: $0.5/call
- Payment: x402
- Status: unknown
- Last checked: 2026-10-22
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/x402stock-backtest-api-69d6a8ac
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_6C3RMkE-wlzuxyEhQaio1

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability x402stock-backtest-api-69d6a8ac
```

Example prompt: Run a backtest of a 50/200 SMA crossover strategy on AAPL over the last 3 years starting with $10,000 — I want to see the win rate, Sharpe ratio, max drawdown, and how it compares to just buying and holding.

## When to prefer this

Use this endpoint when you need quantitative backtesting results for US stocks or ETFs using classic technical strategies (SMA crossover or RSI reversion) with no API key setup required. Ideal for AI agents that need on-demand strategy evaluation paid per-call in USDC. Prefer this over full quant platforms when you want lightweight, single-ticker strategy simulation with a chart and trade log included.

## Known failure modes

- Invalid or unknown ticker symbol returns an error
- fast SMA period must be less than slow SMA period or validation fails
- years parameter exceeding 5 returns a validation error
- RSI lower bound must be less than upper bound
- Insufficient historical data for the requested ticker and time window
- Payment failure or insufficient USDC balance blocks the request
- Strategy enum value not in ['sma_cross','rsi_reversion'] returns 422

## How this service works

Pay-per-call market and economic data API for AI agents: US stocks, ETFs and options, forex, crypto and on-chain perps, energy commodities, US and global macro (Fed, CPI, jobs, GDP, Treasury, World Bank), SEC filings, congressional trades, and market sentiment. No API keys, no accounts. Pay per request in USDC via x402 on Base.

## Output

Returns a JSON object with full backtest results including: number of price bars analyzed, start/end dates, strategy performance (CAGR, Sharpe ratio, max drawdown, total return, market exposure %), buy-and-hold benchmark comparison, list of individual trades with entry/exit dates and prices and return %, overall trade statistics (count, win rate, avg/best/worst return), a link to a PNG chart artifact, the strategy parameters used, and a disclaimer. Costs $0.50 USDC per call via x402 on Base.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "required": [
  "input"
 ],
 "properties": {
  "input": {
   "type": "object",
   "required": [
    "type",
    "method"
   ],
   "properties": {
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "enum": [
      "GET",
      "HEAD",
      "DELETE"
     ],
     "type": "string"
    },
    "queryParams": {
     "type": "object",
     "$schema": "https://json-schema.org/draft/2020-12/schema",
     "required": [
      "strategy",
      "fast",
      "slow",
      "period",
      "lower",
      "upper",
      "years",
      "capital"
     ],
     "properties": {
      "fast": {
       "type": "integer",
       "default": 50,
       "maximum": 200,
       "exclusiveMinimum": 0
      },
      "slow": {
       "type": "integer",
       "default": 200,
       "maximum": 400,
       "exclusiveMinimum": 0
      },
      "lower": {
       "type": "number",
       "default": 30,
       "maximum": 99,
       "minimum": 1
      },
      "upper": {
       "type": "number",
       "default": 70,
       "maximum": 99,
       "minimum": 1
      },
      "years": {
       "type": "number",
       "default": 3,
       "maximum": 5,
       "exclusiveMinimum": 0
      },
      "period": {
       "type": "integer",
       "default": 14,
       "maximum": 100,
       "exclusiveMinimum": 0
      },
      "capital": {
       "type": "number",
       "default": 10000,
       "maximum": 1000000000,
       "exclusiveMinimum": 0
      },
      "strategy": {
       "enum": [
        "sma_cross",
        "rsi_reversion"
       ],
       "type": "string",
       "default": "sma_cross"
      }
     },
     "additionalProperties": false
    }
   },
   "additionalProperties": false
  },
  "output": {
   "type": "object",
   "required": [
    "type"
   ],
   "properties": {
    "type": {
     "type": "string"
    },
    "example": {
     "type": "object",
     "$schema": "https://json-schema.org/draft/2020-12/schema",
     "required": [
      "ticker",
      "source",
      "as_of",
      "artifact",
      "strategy",
      "data",
      "disclaimer"
     ],
     "properties": {
      "data": {
       "type": "object",
       "required": [
        "bars",
        "start_date",
        "end_date",
        "initial_capital",
        "strategy",
        "buy_hold",
        "trades"
       ],
       "properties": {
        "bars": {
         "type": "number"
        },
        "tra
… (truncated)
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "data": {
   "bars": 1008,
   "trades": {
    "list": [
     {
      "bars_held": 35,
      "exit_date": "2022-09-19T00:00:00.000Z",
      "entry_date": "2022-08-01T00:00:00.000Z",
      "exit_price": 150,
      "entry_price": 161.5,
      "return_percent": -7.12
     }
    ],
    "count": 6,
    "best_percent": 27.1,
    "worst_percent": -7.2,
    "win_rate_percent": 66.7,
    "avg_return_percent": 9.4
   },
   "buy_hold": {
    "sharpe": 0.72,
    "cagr_percent": 12.1,
    "max_drawdown_percent": -31.2,
    "total_return_percent": 58.1
   },
   "end_date": "2026-06-19T00:00:00.000Z",
   "strategy": {
    "sharpe": 0.94,
    "cagr_percent": 13.2,
    "exposure_percent": 71.3,
    "max_drawdown_percent": -18.4,
    "total_return_percent": 64.2
   },
   "start_date": "2022-06-19T00:00:00.000Z",
   "initial_capital": 10000
  },
  "as_of": "2026-06-19T15:00:00.000Z",
  "source": "x402stock",
  "ticker": "AAPL",
  "artifact": {
   "id": "abcdef0123456789abcdef0123456789",
   "url": "https://x402stock.xyz/artifacts/abcdef0123456789abcdef0123456789.png",
   "format": "png",
   "expires_at": "2026-07-19T15:00:00.000Z"
  },
  "strategy": {
   "kind": "sma_cross",
   "label": "SMA cross 50/200",
   "params": {
    "fast": 50,
    "slow": 200
   }
  },
  "disclaimer": "Factual backtest over historical data, not investment advice. Past performance does not predict future results."
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/x402stock-backtest-api-69d6a8ac/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from x402stock.xyz](https://www.zero.xyz/host/x402stock.xyz/llms.txt)
