Lab / Option pricing demo
Option pricing demo
Price a European option with the Black–Scholes library I wrote in C++, compiled to WebAssembly and running in this browser tab: its closed-form price and Greeks, its implied-volatility solver, and its seeded Monte Carlo pricer beside the closed form.
How it works
The page loads black-scholes-options’ WebAssembly build from release v0.1.0, commit 404ceed, compiled from the library’s C++17 headers with Emscripten 6.0.13. It runs only in this browser tab: nothing you enter is sent anywhere. Every price, Greek, volatility and estimate on the page is a call to that module; the chart is 21 calls, one for each spot. New seed draws a seed with crypto.getRandomValues.
It is a study, not a trading tool: a European option under the Black–Scholes model, with a constant rate and volatility, no dividends and no early exercise. The library’s checks show that it computes the model, not that the model describes a market. Vega is per volatility point (1%); theta is per calendar day (a year over 365), the change in value as one day passes, so usually negative. Monte Carlo is an estimate with its own estimated standard error, and its 95% interval is not a guarantee: the guidance beside each run comes from the library’s measurements, at S = 100, T = 1 year and r = 3% only (README, “What is and is not guaranteed”).
The module agrees with the library’s native build to a stated tolerance, not bit for bit: the two use different maths libraries, and the native arm64 build fuses multiplies and adds. Over the library’s test grid and two samples of 20,000 points, every price and Greek agreed within 10−12 of the size of the terms its formula combines (S + K e−rT for the price), the largest difference 2.15 × 10−14 of that; implied volatilities within 10−7 vol points wherever the price determines the volatility; and seeded Monte Carlo, which draws the same random numbers in both, to a relative 1.31 × 10−14 over 20 runs of 106 paths. The library tested the module in Node on macOS.
The limits are the module’s: spot and strike 0.01 to 1,000,000; time to expiry 0.0001 to 100 years; volatility 0.01% to 1,000%; rate −10% to 100%; 1,000 to 2,000,000 paths and seeds from 0 to 253 − 1. A value outside them is refused, with a message beside its field, and never changed to fit. The number of paths is the only limit on time. Monte Carlo runs on this page’s main thread, as the module is built for, not in a background worker: the library timed its largest call at 0.049 to 0.063 s in Node on an Apple M1 Pro, and 0.099 to 0.111 s in the slowest case it found.