Guides · options

Price an option in 5 lines of Python

One POST request returns the price and full greeks — European (analytic Black-Scholes-Merton) or American (binomial CRR) — with every convention spelled out in the response. No QuantLib build, no C++ toolchain.

01The five lines

python
import requests

r = requests.post("https://quantbox.dev/v1/options/price",
    headers={"X-API-Key": KEY},
    json={"option_type": "call", "spot": 100, "strike": 100,
          "rate": 0.05, "volatility": 0.20, "expiry_years": 1})
print(r.json())
response
{
  "price": 10.4506,
  "greeks": {
    "delta": 0.6368, "gamma": 0.0188, "vega": 37.524,
    "theta": -6.414, "rho": 53.2325, "theta_per_day": -0.0176
  },
  "model": "analytic_black_scholes_merton",
  "conventions": {
    "rate": "continuously compounded, act/365",
    "expiry": "rounded to whole days (error <= 0.5/365 year)",
    "theta": "per year (theta_per_day = theta/365)",
    "vega": "per 1.00 change in volatility (divide by 100 for per-point)",
    "rho": "per 1.00 change in rate (divide by 100 for per-bp x100)"
  }
}

The conventions object ships with every response. That is the point of the API: a number without its day count, compounding and units is a bug waiting to be deployed.

02Reading the greeks

GreekValueMeaning, in these units
delta0.6368Price change per 1.00 move in spot.
gamma0.0188Delta change per 1.00 move in spot.
vega37.524Per 1.00 change in vol — divide by 100 for the usual "per vol point" (0.375 per point).
theta_per_day-0.0176Price decay per calendar day (theta is per year).
rho53.2325Per 1.00 change in rate — 0.0053 per basis point.

03American exercise: change one field

Set "exercise": "american" and the engine switches to a Cox-Ross-Rubinstein binomial tree with 800 steps. Vega and rho are computed by central finite differences (the tree does not provide them analytically).

request · american put
{"option_type": "put", "exercise": "american",
 "spot": 42, "strike": 40, "rate": 0.10,
 "volatility": 0.20, "expiry_years": 0.5}
response (abridged)
{
  "price": 0.9087,
  "greeks": { "delta": -0.2578, "gamma": 0.0627, "vega": 9.271,
              "theta": -1.0398, "rho": -4.0771, "theta_per_day": -0.0028 },
  "model": "binomial_crr_800_steps"
}

The American put is worth more than its European twin (0.8076 with the same inputs) — that difference is the early-exercise premium, and it is exactly what a plain Black-Scholes formula cannot give you.

04Implied volatility: the inverse problem

Given a market price, back out the Black-Scholes vol. Prices outside no-arbitrage bounds return a 422 with the reason, not a cryptic root-finding error.

request
POST /v1/options/implied-vol
{"option_type": "call", "spot": 100, "strike": 105,
 "rate": 0.03, "expiry_years": 0.25, "market_price": 2.10}
response
{ "implied_volatility": 0.1892,
  "conventions": { "exercise": "european only",
                   "volatility": "annualized, decimal (0.20 = 20%)" } }

05Pitfalls the validation catches for you

Decimals, not percents. rate: 0.05 means 5%. Passing 5 gets rejected by the bounds check instead of silently pricing garbage.

Compounding. Rates are continuously compounded. If yours is annually compounded, convert first: r = ln(1 + r_annual).

Dividends. dividend_yield is a continuous yield. Discrete dividend schedules are not supported — flag it if you need them.

Expiry. expiry_years is rounded to whole days; the response says so, and the error bound (≤ 0.5/365 year) is documented rather than hidden.

06Same thing in curl

curl -s https://quantbox.dev/v1/options/price \
  -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d '{"option_type":"call","spot":100,"strike":100,
       "rate":0.05,"volatility":0.20,"expiry_years":1}'

Try it against the real API. Sign up with an email, get a key instantly, and the playground runs this exact call in your browser.

Get a free API key

500 calls/month free · no credit card · full schemas in /docs

Related: Bond duration, convexity and BPV over HTTP · Value-at-Risk and Expected Shortfall in one call