> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sandmark.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Backtesting quickstart

> Backtest a covered call and read the result.

> [!NOTE]
>
> Backtesting is an add-on with its own API key, separate from your volatility data key. Both go in the
> `X-API-Key` header.

**1. Describe the strategy**

Sell a 20-delta BTC call on the front monthly expiry, at least 20 days out. Take profit when 75% of the
premium has decayed, stop out if the call's delta reaches 0.45, and roll two days before expiry. Save the
following as `covered-call.json`:

```json covered-call.json theme={null}
{
  "name": "BTC 20-delta covered call",
  "asset": "DER.BTC_USD",
  "start": "2026-05-01",
  "end": "2026-10-31",
  "capital": { "initial_equity": 1, "sizing": { "mode": "contracts", "value": 1 } },
  "structure": {
    "expiry": { "by": "monthly", "min_dte": 20 },
    "legs": [
      { "id": "call", "type": "call", "direction": "short", "strike": { "by": "delta", "value": 0.20 } }
    ]
  },
  "lifecycle": {
    "rules": [
      { "name": "take_profit_75",
        "when": { "predicate": { "subject": "structure", "metric": "premium", "op": "below",
                                 "value": -0.75, "unit": "percent", "reference": "entry" } },
        "do": { "action": "close_all" } },
      { "name": "delta_stop",
        "when": { "predicate": { "subject": "leg:call", "metric": "contract_delta", "op": "above", "value": 0.45 } },
        "do": { "action": "close_all" } },
      { "name": "roll_before_expiry",
        "when": { "predicate": { "subject": "structure", "metric": "dte", "op": "below", "value": 2 } },
        "do": { "action": "close_all" } }
    ]
  }
}
```

`initial_equity: 1` with one contract models one BTC held against the short call.

**2. Run it**

```bash cURL theme={null}
curl -X POST https://api.sandmark.com/backtesting/v1/backtest \
  -H "X-API-Key: $SANDMARK_BACKTEST_KEY" \
  -H "Content-Type: application/json" \
  --data @covered-call.json
```

```python Python theme={null}
import json
import os

import requests

BASE_URL = "https://api.sandmark.com/backtesting"

with open("covered-call.json") as f:
    spec = json.load(f)

response = requests.post(
    f"{BASE_URL}/v1/backtest",
    headers={"X-API-Key": os.environ["SANDMARK_BACKTEST_KEY"]},
    json=spec,
    timeout=180,
)
response.raise_for_status()
result = response.json()

stats = result["stats"]
print(result["strategy"]["headline"])
print(f"Return {stats['total_return']:+.1%}  Sharpe {stats['sharpe']:.2f}  "
      f"Max drawdown {stats['drawdown']['max_drawdown']:.1%}  Trades {stats['trades']['count']}")
for warning in result["warnings"]:
    print("warning:", warning)
```

A six-month run takes a few seconds:

```text theme={null}
Short call
Return -0.1%  Sharpe 0.02  Max drawdown -8.8%  Trades 14
warning: only 14 positions: ratio estimates are dominated by noise below ~30
```

Eleven of the 14 trades hit the take-profit, but two delta stops, in August and September, gave the
gains back. The `positions` array shows each trade's `reason`, so you can see which rule closed it. The warning is the engine telling you six months
is too short to judge a monthly strategy; widen the window if your lookback allows.

**3. Get the report**

Add `format=html` for a self-contained report with the equity curve, drawdowns and trade table, ready to
open or share:

```bash theme={null}
curl -X POST "https://api.sandmark.com/backtesting/v1/backtest?format=html&theme=dark" \
  -H "X-API-Key: $SANDMARK_BACKTEST_KEY" \
  -H "Content-Type: application/json" \
  --data @covered-call.json \
  -o covered-call.html
```

`format=xlsx` gives an Excel workbook and `format=csv` a zip of trades, positions and equity.

## Next steps

> [card] [Reading the result](https://docs.sandmark.com/backtesting/results.md)
>
> What every statistic, trade field and warning means.

> [card] [Strategy specification](https://docs.sandmark.com/backtesting/strategy-spec.md)
>
> Change the legs, expiry, sizing, exits, hedge and costs.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.