A covered call pays you a premium in exchange for capping your upside. Whether that trade beats simply holding the shares depends on how often the stock runs past your strike. This guide builds a small backtest in Python. It pulls daily candles from the Mboum API, computes a 30-day volatility figure from them, estimates each month's premium with a pricing model, and compares the result with buy-and-hold. It also states clearly what a backtest like this cannot tell you.
What this backtest uses, and what it can't
Mboum's options endpoints return current chains, plus a past day's unusual-activity list. They do not return a history of quotes for a chosen contract. So the premiums here are model estimates, not prices that traded:
- Prices: daily candles from the history endpoint.
- Volatility: the v3 chain's
historicVolatility30dfield is a current value for each contract, not a time series. The script computes its own 30-day figure from the candles instead. - Premium: a Black-Scholes call price that uses that realized volatility in place of implied volatility. Implied volatility often differs from realized volatility, so treat the premiums as rough.
Prerequisites
- Python 3.9+ and the
requestslibrary. - A Mboum API key. The free plan is enough, because the whole backtest uses one request.
The endpoint
GET https://api.mboum.com/v1/markets/stock/history has weight 1. Send ticker and interval=1d to get daily candles for the last 5 years. The body is keyed by Unix timestamp, and each candle has date, date_utc, open, high, low, close and volume, plus adjclose when available. The shape looks like this (values are illustrative):
{
"meta": { "symbol": "KO", "status": 200 },
"body": {
"1731076200": {
"date": "2024-11-08",
"date_utc": 1731076200,
"open": 69.1,
"high": 69.8,
"low": 68.9,
"close": 69.5,
"volume": 11250000,
"adjclose": 68.7
}
}
}
If you add diffandsplits=true, an events key appears inside body next to the candles. The script skips it. See the API documentation for the full parameter list.
The rules
- Every 21 trading days, own the shares and sell one call 5% above that day's close, expiring 21 trading days later.
- Estimate the premium with Black-Scholes, using the realized volatility of the last 30 daily returns and an assumed 4% risk-free rate.
- At expiration, if the close is above the strike, the shares are called away at the strike. Otherwise you keep them and sell a new call.
- Each cycle's return is the capped stock gain plus the premium, divided by the starting price.
One cycle by hand
These are made-up numbers, worked through the same rules. A stock closes at $70.00, so the call strike is $73.50. With 16% realized volatility, a 4% rate and 21 trading days to go, the model prices the call at about $0.28, or 0.4% of the share price. Three things can happen:
- The stock closes at $72.00. It stays below the strike. You gain $2.00 on the shares and keep the $0.28, for $2.28, or 3.26%. Holding alone made 2.86%.
- The stock closes at $76.00. The shares are called away at $73.50. You gain $3.50 plus $0.28, for $3.78, or 5.40%. Holding alone made 8.57%.
- The stock closes at $66.00. You lose $4.00 on the shares and keep the $0.28, for a loss of $3.72, or 5.31%. Holding alone lost 5.71%.
The premium cushions a drop by a small amount, and the strike removes the gain above it. The backtest repeats this arithmetic for every cycle in the data.
The volatility estimate matters a great deal. In the same example, doubling the volatility to 32% raises the modeled premium from about $0.28 to about $1.32. That is why the best-practices list below suggests checking your figure against the chain.
The script
import math
import statistics
from datetime import datetime, timezone
import requests
URL = "https://api.mboum.com/v1/markets/stock/history"
HEADERS = {"Authorization": "Bearer YOUR_MBOUM_API_KEY"}
TICKER = "KO"
RATE = 0.04 # assumed risk-free rate
OTM = 0.05 # sell calls 5% above the price
HOLD = 21 # trading days per cycle
VOL_WINDOW = 30 # daily returns in the volatility estimate
def get_rows(ticker):
resp = requests.get(
URL,
headers=HEADERS,
params={"ticker": ticker, "interval": "1d"},
timeout=30,
)
resp.raise_for_status()
data = resp.json()
body = data.get("body")
if data.get("success") is False or not body:
raise SystemExit(f"No data returned: {data.get('message')}")
rows = [
v for k, v in body.items()
if k != "events" and v.get("close") is not None
]
rows.sort(key=lambda r: r["date_utc"])
return [
(datetime.fromtimestamp(r["date_utc"], timezone.utc).date(), r["close"])
for r in rows
]
def norm_cdf(x):
return 0.5 * (1 + math.erf(x / math.sqrt(2)))
def bs_call(spot, strike, years, rate, vol):
if vol <= 0 or years <= 0:
return max(spot - strike, 0.0)
root = vol * math.sqrt(years)
d1 = (math.log(spot / strike) + (rate + 0.5 * vol ** 2) * years) / root
d2 = d1 - root
return spot * norm_cdf(d1) - strike * math.exp(-rate * years) * norm_cdf(d2)
def realized_vol(closes):
returns = [math.log(b / a) for a, b in zip(closes, closes[1:])]
return statistics.stdev(returns) * math.sqrt(252)
def backtest(rows):
closes = [c for _, c in rows]
cycles = []
i = VOL_WINDOW
while i + HOLD < len(closes):
spot = closes[i]
vol = realized_vol(closes[i - VOL_WINDOW:i + 1])
strike = spot * (1 + OTM)
premium = bs_call(spot, strike, HOLD / 252, RATE, vol)
final = closes[i + HOLD]
stock_pnl = min(final, strike) - spot
cycles.append({
"date": rows[i][0],
"vol": vol,
"premium_yield": premium / spot,
"assigned": final > strike,
"cc_return": (stock_pnl + premium) / spot,
"hold_return": (final - spot) / spot,
})
i += HOLD
return cycles
def summarize(cycles):
n = len(cycles)
cc = math.prod(1 + c["cc_return"] for c in cycles) - 1
hold = math.prod(1 + c["hold_return"] for c in cycles) - 1
avg_yield = sum(c["premium_yield"] for c in cycles) / n
print(f"Cycles: {n}")
print(f"Average volatility: {sum(c['vol'] for c in cycles) / n:.1%}")
print(f"Average premium per cycle: {avg_yield:.2%}")
print(f"Annualized premium yield: {avg_yield * 252 / HOLD:.1%}")
print(f"Called away: {sum(c['assigned'] for c in cycles) / n:.0%} of cycles")
print(f"Covered call return: {cc:.1%}")
print(f"Buy and hold return: {hold:.1%}")
if __name__ == "__main__":
summarize(backtest(get_rows(TICKER)))
Reading the output
The script prints seven lines. Here is what each one tells you:
- Annualized premium yield: the average premium per cycle, scaled to a year. It is the income the model says the calls would have paid.
- Called away: the share of cycles where the stock closed above the strike. Each one capped your gain for that month.
- Covered call vs. buy and hold: both are compounded over the same span. A covered call gives up upside in strong rallies and cushions flat or down months by the premium, so the gap usually depends on how the stock behaved during the period you tested.
Your numbers depend on the ticker and the 5 years of data the endpoint returns.
Best practices
- Cache the candles. Daily history changes once a day. Save the response to disk and rerun the backtest with different settings at no extra cost.
- Sweep the settings. Try
OTMvalues of 2%, 5% and 10%, and differentHOLDlengths. One setting can look good by luck. - Sanity-check the volatility. Compare your latest 30-day figure with the
historicVolatility30dfield from/v3/markets/options(weight 2). The two may differ, because the field's method is not documented. - Remember what is missing. The model ignores dividends, commissions, taxes, bid-ask spreads and early assignment, and the 21-day cycles are not aligned to real expiration dates. Real results will differ.
This is a study of past prices and modeled premiums. It is for information only and is not investment advice.
Next steps
Get a free API key at mboum.com/pages/api and browse every endpoint in the API documentation.