# Strategy Optimizer

> Strategy Optimizer is a paid API for AI agents from grok-backtest-api.fly.dev, paid per call via x402, $0.5/call, status unknown (last checked 2026-10-31).

Grid-searches strategy parameter combinations across Coinbase daily candles and returns recommended, overfitting-flagged, and ranked parameter sets for crypto quant strategies.

## Facts

- Endpoint: POST https://grok-backtest-api.fly.dev/optimize?utm_source=zero.xyz
- Price: $0.5/call
- Payment: x402
- Status: unknown
- Last checked: 2026-10-31
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/strategy-optimizer-7bd60268
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_-1EIIt67-YyoXO_DhEElD

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 strategy-optimizer-7bd60268 -d '<json body>'
```

Example prompt: Run a parameter grid search on a momentum crypto strategy — try lookbacks of 10, 20, and 30 with risk_per_trade values of 0.02 and 0.05 and atr_mult of 1, 2, and 3 — using the point-in-time top 50 coins universe from 2022-01-01 to 2024-12-31, with 0.1% slippage and 0.05% fee, starting with $100,000, and rank by robustness so I can see which combo holds up across both halves without overfitting.

## When to prefer this

Choose this endpoint when you need to systematically evaluate multiple parameter combinations for a crypto trading strategy and want overfitting protection via half-period return comparison and robust scoring — as opposed to running a single backtest. Prefer this over the Crypto Backtest endpoint when you have uncertainty about optimal parameter values and want a ranked shortlist with regime-stability checks included in one call.

## Known failure modes

- Invalid strategy type enum value returns 422 validation error
- Grid parameter values incompatible with strategy type cause computation errors
- Date range with insufficient candle history returns empty or error result
- Universe mode 'point_in_time' with no eligible coins returns empty universe error
- Slippage or fee values exceeding maximum (0.05) return 422 validation error
- Payment not provided or insufficient USDC causes 402 Payment Required response
- Very large grids may exceed compute limits and return truncated results

## How this service works

Grid-search up to 50 parameter combos of a backtest strategy; ranks by worst-half (H1/H2) return with neighbourhood smoothing, flags overfitting, and recommends the most robust parameters rather than the best-fit ones.

## Output

A JSON object containing the total and executed combo count, a recommended parameter set (ranked by the chosen method), the best-by-return parameters, per-combo return and robust scores, half-period returns for overfitting detection, a summary with percent profitable and median return, and a list of overfitting flags with details.

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "properties": {
  "end": {
   "anyOf": [
    {
     "type": "string"
    },
    {
     "type": "null"
    }
   ]
  },
  "fee": {
   "type": "number",
   "maximum": 0.05,
   "minimum": 0
  },
  "grid": {
   "type": "object",
   "additionalProperties": {
    "type": "array",
    "items": {
     "anyOf": [
      {
       "type": "integer"
      },
      {
       "type": "number"
      },
      {
       "type": "string"
      },
      {
       "type": "null"
      }
     ]
    }
   }
  },
  "start": {
   "anyOf": [
    {
     "type": "string"
    },
    {
     "type": "null"
    }
   ]
  },
  "rank_by": {
   "enum": [
    "robust",
    "return"
   ],
   "type": "string"
  },
  "slippage": {
   "type": "number",
   "maximum": 0.05,
   "minimum": 0
  },
  "strategy": {
   "type": "object",
   "required": [
    "type"
   ],
   "properties": {
    "type": {
     "enum": [
      "breakout",
      "momentum",
      "dip",
      "ma_trend"
     ],
     "type": "string"
    },
    "params": {
     "type": "object",
     "additionalProperties": true
    }
   },
   "additionalProperties": false
  },
  "universe": {
   "type": "object",
   "properties": {
    "mode": {
     "enum": [
      "point_in_time",
      "current_top",
      "fixed"
     ],
     "type": "string"
    },
    "coins": {
     "anyOf": [
      {
       "type": "array",
       "items": {
        "type": "string"
       },
       "maxItems": 200
      },
      {
       "type": "null"
      }
     ]
    },
    "top_n": {
     "type": "integer",
     "maximum": 200,
     "minimum": 5
    },
    "min_age_days": {
     "type": "integer",
     "maximum": 120,
     "minimum": 0
    },
    "min_avg_dollar_volume": {
     "type": "number",
     "minimum": 0
    }
   },
   "additionalProperties": false
  },
  "initial_capital": {
   "type": "number",
   "maximum": 1000000000,
   "exclusiveMinimum": 0
  }
 }
}
```

## Response schema (JSON Schema)

```json
{
 "type": "json",
 "example": {
  "summary": {
   "pct_profitable": 55.6,
   "median_return_pct": 1.2
  },
  "truncated": false,
  "combos_run": 18,
  "recommended": {
   "params": {
    "atr_mult": 2,
    "lookback": 20,
    "risk_per_trade": 0.05
   },
   "return_pct": 10.98,
   "robust_score": -11.97,
   "h1_return_pct": -6.97,
   "h2_return_pct": 19.88
  },
  "combos_total": 18,
  "best_by_return": {
   "params": {
    "atr_mult": 2,
    "lookback": 10,
    "risk_per_trade": 0.05
   }
  },
  "overfitting_flags": [
   {
    "id": "best_return_not_robust",
    "detail": "..."
   }
  ]
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/strategy-optimizer-7bd60268/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from grok-backtest-api.fly.dev](https://www.zero.xyz/host/grok-backtest-api.fly.dev/llms.txt)
