options-pricer

API reference: https://ikerabad.github.io/options-pricer/
European, American and path-dependent option pricing in Python: closed-form
Black-Scholes, Monte Carlo with antithetic variates, implied volatility by root
finding, SVI calibration across a term structure, a binomial tree for early
exercise and path simulation for Asians and barriers. Every number in this
README comes from a command you can run.
Results
Reference case: spot 100, strike 100, rate 5%, volatility 20%, expiry 1 year.
| Quantity |
Value |
| Black-Scholes call |
10.450584 |
| Delta |
0.636831 |
| Gamma |
0.018762 |
| Vega |
37.524035 |
| Theta |
-6.414028 |
| Rho |
53.232482 |
| Vanna |
-0.281430 |
| Volga |
9.850059 |
| Charm |
-0.065667 |
| Monte Carlo, 1,000,000 paths |
10.456536 |
| Standard error |
0.014737 |
| 95% interval |
[10.427652, 10.485419] |
The analytic price falls inside the Monte Carlo interval. The standard error
falls with the square root of the number of paths, which is what the first plot
shows.
SVI calibration on a synthetic smile with 0.1 % relative price noise:
| Parameter |
True |
Fitted |
| a |
0.02 |
0.022490 |
| b |
0.15 |
0.144749 |
| rho |
-0.4 |
-0.423434 |
| m |
-0.05 |
-0.051059 |
| sigma |
0.15 |
0.138244 |
RMSE in implied volatility: 0.021 vol points.
Four expiries, calibrated from short to long and chained through the previous
slice. The quotes come from a synthetic term structure with 0.1 % price noise.
| Expiry |
a |
b |
rho |
m |
sigma |
RMSE |
| 0.25 |
0.0072 |
0.0867 |
-0.326 |
-0.020 |
0.136 |
0.001431 |
| 0.50 |
0.0145 |
0.0985 |
-0.347 |
-0.042 |
0.151 |
0.000682 |
| 1.00 |
0.0251 |
0.1205 |
-0.368 |
-0.071 |
0.184 |
0.000832 |
| 2.00 |
0.0651 |
0.0954 |
-0.346 |
-0.075 |
0.153 |
0.000278 |
a grows with maturity, which is the shape you expect when short-dated
volatility is higher than long-dated volatility.
Options on a forward
Black-76 is the same model with the spot replaced by the forward. With
F = 100 * exp(0.05) = 105.1271, K = 100, r = 5 %, vol = 20 % and one
year:
| Quantity |
Value |
| Call price |
10.450584 |
| Delta |
0.605772 |
| Gamma |
0.016977 |
| Vega |
37.524035 |
The price matches Black-Scholes when the forward is the theoretical one, which
is the consistency check in the tests.
American options
Prices from a Cox-Ross-Rubinstein tree with 1,000 steps, same reference case:
| Option |
American |
European |
Premium |
| Put |
6.089595 |
5.571527 |
0.518069 |
| Call, no dividend |
10.448584 |
10.448584 |
0.000000 |
| Call, 8% dividend yield |
6.541188 |
6.141112 |
0.400076 |
The put carries a real premium because waiting has a cost: the strike is
discounted and the downside is protected today. The call without dividends has
no premium, which is the standard no-arbitrage result. Adding a dividend yield
changes that, and the tree finds the value of the early exercise right.
Real market data
data/binance_btc_options_2026-11-22.csv is a snapshot of the Binance BTC
options chain, captured on 2026-11-22 at 20:22 UTC with the index at 60,637.68
USDT. It holds 446 quotes across three expiries, calls and puts, filtered to
positive bid and ask, mid above 1 USDT, a relative spread below 50 % and
moneyness between 0.5 and 2.
The forward for each expiry comes from put-call parity on the pair closest to
the index, with a zero rate. SVI is fitted directly to the market implied
volatilities, which avoids the quote conversion that an inverse contract would
need.
| Expiry |
Days |
Forward |
Quotes |
RMSE |
| 2026-12-25 |
32.5 |
60,875.00 |
75 |
1.86 vol points |
| 2027-01-29 |
67.5 |
61,127.50 |
85 |
0.38 vol points |
| 2027-03-26 |
123.5 |
61,627.50 |
78 |
0.62 vol points |
Quotes are weighted by the inverse of their relative bid-ask spread, so the fit
leans on the liquid strikes instead of treating a tight quote and a wide one as
equally informative.
The short expiry is the hard one. A five-parameter SVI cannot follow the full
curvature of a 33-day crypto smile, and the fit leaves 1.57 vol points of RMSE.
That is visible in the last figure and it is reported, not hidden.
The snapshot is downloaded by scripts/fetch_binance.py and versioned so the
repository works without network access. scripts/real_smile.py rebuilds the
figure from the CSV.
The same pipeline runs on ETH, with 200 quotes and RMSE between 0.45 and 1.37
vol points. The two extra figures show the ETH smile and the three BTC slices in
three dimensions.
Calibration time on one real slice, ten repetitions:
| Constraint |
Median |
Minimum |
Maximum |
| Soft penalty |
14.80 ms |
14.72 ms |
14.92 ms |
| Hard SLSQP |
16.44 ms |
16.33 ms |
16.80 ms |
Monte Carlo throughput with one million paths, median of five runs:
| Mode |
Median |
Paths per second |
| Antithetic |
21.17 ms |
47,235,763 |
| Plain |
24.04 ms |
41,603,222 |
Black-Scholes throughput, 100,000 prices with strikes from 80 to 120:
| Time |
Prices per second |
| 84.9 ms |
1,178,285 |
The closed form uses math.erfc instead of scipy.stats.norm.cdf. The change
multiplied throughput by a hundred and left every price bit-for-bit identical.
The vectorised path takes one million prices at once:
| Time |
Prices per second |
| 30.2 ms |
33,087,603 |
The binomial tree with 1,000 steps takes 12.5 ms. The price vector is updated
incrementally as the tree walks back, instead of being rebuilt at every step,
which cut the time from 31.1 ms.
Out-of-sample error and bootstrap intervals on the real BTC snapshot. The model
is fitted on two thirds of the strikes and scored on the rest:
| Expiry |
Train RMSE |
Test RMSE |
a interval |
b interval |
| 2026-12-25 |
0.014913 |
0.017500 |
[-0.0500, -0.0148] |
[0.1324, 0.1999] |
| 2027-01-29 |
0.002176 |
0.002023 |
[-0.0500, 0.0056] |
[0.1253, 0.1969] |
| 2027-03-26 |
0.003454 |
0.003798 |
[-0.0368, 0.0245] |
[0.1431, 0.2084] |
The test error stays close to the train error, so the fit generalises to strikes
it never saw. The interval for a hits the lower bound on two slices, which is
the honest reading: five SVI parameters are not uniquely identified by a handful
of quotes, and a and b trade off against each other.
SSVI fits one surface with three parameters instead of five per expiry. On the
same snapshot:
| Expiry |
SVI RMSE |
SSVI RMSE |
| 2026-12-25 |
0.018607 |
0.055685 |
| 2027-01-29 |
0.002250 |
0.017037 |
| 2027-03-26 |
0.003533 |
0.015304 |
SSVI is arbitrage free with rho -0.3318, eta 1.0639 and gamma 0.5000. It fits
worse, as expected: three parameters cannot follow three independent smiles. The
trade is consistency against accuracy, and the calibration is explicit about it.
Multi-day calibration
Five daily BTC chains reconstructed from Binance option klines, 2026-11-19 to
2026-11-23, with SHA-256 and provenance in data/history/manifest.json.
Parameters for the 2026-12-25 expiry. RMSE in vol points.
| Date |
Quotes |
a |
b |
rho |
m |
sigma |
RMSE |
| 2026-11-19 |
41 |
0.0027 |
0.0870 |
-0.190 |
0.043 |
0.162 |
3.55 |
| 2026-11-20 |
48 |
0.0109 |
0.0879 |
-0.275 |
0.072 |
0.110 |
6.47 |
| 2026-11-21 |
57 |
0.0218 |
0.1492 |
+0.224 |
-0.008 |
0.017 |
30.23 |
| 2026-11-22 |
42 |
0.0130 |
0.1004 |
-0.369 |
-0.028 |
0.105 |
12.24 |
| 2026-11-23 |
48 |
-0.0251 |
0.1258 |
-0.063 |
0.078 |
0.325 |
4.33 |
The calibration is not stable over this series. Only b stays in a reasonable
band. a, rho and m change sign, sigma varies by a factor of 19, and
2026-11-21 ends with 30 vol points of RMSE because the smile explodes in the
wings.
The likely cause is the data, not the optimiser: daily closes are last trades,
not mids, and each day has 41 to 57 quotes for that expiry. Five SVI parameters
are not identified by that few points. The full analysis is in
docs/time_series.md.
Path-dependent options
Asian and barrier options are priced by Monte Carlo over full price paths. The
table uses 200,000 paths and 100 steps.
| Option |
Price |
Standard error |
| Asian call, arithmetic average |
5.797045 |
0.017937 |
| Up-and-out call, barrier 120 |
1.424428 |
0.007951 |
| Up-and-out call, barrier 150 |
7.854730 |
0.024648 |
| Up-and-out call, barrier 200 |
10.363996 |
0.032452 |
| European call |
10.450584 |
analytic |
The Asian is much cheaper than the European because averaging removes variance.
The barrier converges to the European price as the level moves away, which is
what the last figure shows.
Barriers are monitored at the simulation steps, not continuously. That
overprices knock-outs slightly, because a path can cross and come back between
two steps. The code does not pretend otherwise.
Greeks
Delta, gamma and vega for both families come from two independent estimators.
Finite differences with common random numbers reprice with the same seed, so the
Monte Carlo noise cancels. The likelihood ratio keeps the payoff fixed and
differentiates the density instead.
| Option |
Method |
Delta |
Gamma |
Vega |
Time |
| Asian call |
FD, common paths |
0.15 % |
2.14 % |
0.26 % |
1.33 s |
| Asian call |
FD, independent paths |
0.32 % |
123.55 % |
0.93 % |
1.29 s |
| Asian call |
Likelihood ratio |
0.72 % |
0.44 % |
2.82 % |
4.60 s |
| Up-and-out, barrier 120 |
FD, common paths |
50.33 % |
103.79 % |
5.77 % |
1.27 s |
| Up-and-out, barrier 120 |
FD, independent paths |
43.01 % |
243.05 % |
7.84 % |
1.29 s |
| Up-and-out, barrier 120 |
Likelihood ratio |
2.20 % |
13.13 % |
1.21 % |
4.27 s |
Errors are relative to a likelihood-ratio reference with 2,000,000 paths. The
continuous-monitoring and likelihood-ratio derivations are in docs/math.md.
The barrier is where the two methods separate. Finite differences differentiate
a discontinuous payoff, so a bump moves paths across the barrier and the
estimator does not converge. The likelihood ratio keeps the payoff fixed and
moves the density, so the discontinuity never enters. It costs more time and its
vega has a larger variance, which is why it uses a million paths here.
Delta, vega and theta for the barrier at 200 come from bump and reprice with
common random numbers: 0.623412, 33.576223 and -5.987842. Gamma is not reported
because the second difference is the same order as the Monte Carlo noise at
these path counts.
No arbitrage
Two conditions are checked on every calibrated slice.
Butterfly. Gatheral's function
g(k) = (1 - k w' / (2 w))^2 - (w'^2 / 4) (1 / w + 1 / 4) + w'' / 2
must be non-negative at every log moneyness. A negative value means the implied
density is negative somewhere, which no arbitrage-free distribution can produce.
Calendar. Total variance must not decrease with maturity at a fixed log
moneyness: w(k, T2) >= w(k, T1) for T2 > T1.
On the real snapshot the three slices are butterfly-free: zero per cent of the
grid points violate g >= 0. Calendar is tighter. Fitting each expiry
independently leaves a gap between the first two expiries, so the long slice is
refitted with the constraint imposed by SLSQP. The gap becomes -8.55e-14, which
is numerical noise, and the price is a worse fit: with weights and the hard
constraint, the last two slices land at 0.0038 and 0.0062 of RMSE.
The hard constraint is opt-in through hard_calendar=True. SLSQP can fail to
converge on a difficult slice, so the default remains the soft penalty.
That is a soft constraint, not a theorem. A hard guarantee needs an optimizer
with explicit non-linear constraints, and it is not implemented.
What it does
- Black-Scholes prices and first and second order Greeks for European calls and
puts.
- Vectorised Black-Scholes prices for arrays of spot and strike.
- Vectorised deltas and vegas for arrays.
- Black-76 prices, forward Greeks and implied volatility for options on a
forward.
- Monte Carlo under the exact lognormal terminal distribution, not an Euler
discretisation, with antithetic variates, standard error and a 95 % interval.
- Implied volatility by Brent root finding, with an explicit rejection of prices
outside the no-arbitrage range.
- SVI total-variance calibration by bounded least squares with a soft L1 loss.
- One slice per expiry, chained in time and regularised towards the previous
slice, plus a 3D surface by interpolation in log time.
- American and European prices on the same binomial tree, with the early
exercise premium measured directly.
- Asian and barrier options by Monte Carlo over simulated paths, with optional
antithetic sampling and a Brownian bridge approximation for continuous
monitoring.
- Path-dependent Greeks by finite differences with common paths and by
likelihood ratio, compared against each other.
- Barrier delta, vega and theta by bump and reprice with common random numbers.
- SVI calibration on a versioned real snapshot of the Binance BTC options
chain, not only on synthetic data.
- Five daily BTC chains with a stability report that publishes the unstable days.
- Quotes weighted by the inverse relative bid-ask spread.
- SSVI and bootstrap intervals available from the command line.
- A
real command that calibrates a versioned snapshot end to end.
- Dependency audit with pip-audit in CI.
- Butterfly and calendar diagnostics, plus a soft calendar penalty between
consecutive expiries.
- Six figures that regenerate from a script.
Install
pip install options-pricer
From the repository, with the development tools:
python -m venv .venv
.venv\Scripts\activate
pip install -e ".[dev]"
pytest
Use