Skip to main content

Black-Scholes Options Pricer

Prices European call and put options with the Black-Scholes model, computes all five Greeks, and solves for implied volatility. A vectorised NumPy pricing engine with a Streamlit front end.

Live demo →

App screenshot

Features

  • Pricing: European calls and puts, with a continuous dividend yield
  • Greeks: delta, gamma, vega, theta and rho, in trader units (vega and rho per 1%, theta per day)
  • Implied volatility: recovers the volatility implied by a market price, using Newton-Raphson safeguarded by bisection, with no-arbitrage bound checks
  • Charts: price sensitivity to every input, each Greek against spot, and price heatmaps across spot and volatility
  • Vectorised engine: every function accepts scalars or NumPy arrays and broadcasts them, so a whole heatmap is priced in one call with no Python loops
  • Tested: reference values, put-call parity, finite-difference checks on every Greek, and implied-vol round trips

The maths

Pricing formula, Greeks and implied volatility

$$C = S e^{-qT} N(d_1) - K e^{-rT} N(d_2)$$

$$P = K e^{-rT} N(-d_2) - S e^{-qT} N(-d_1)$$

$$d_1 = \frac{\ln(S/K) + \left(r - q + \tfrac{1}{2}\sigma^2\right)T}{\sigma\sqrt{T}}, \qquad d_2 = d_1 - \sigma\sqrt{T}$$

where $S$ is the spot price, $K$ the strike, $T$ the time to expiry in years, $r$ the risk-free rate, $q$ the dividend yield, $\sigma$ the volatility and $N$ the standard normal CDF.

Reading the formula: $N(d_2)$ is the risk-neutral probability that the option finishes in the money, so $K e^{-rT} N(d_2)$ is the present value of the strike you expect to pay. $e^{-qT} N(d_1)$ is the call's delta.

In code, calls and puts share one formula through a sign $s = +1$ (call) or $-1$ (put):

$$V = s\left[S e^{-qT} N(s,d_1) - K e^{-rT} N(s,d_2)\right]$$

Greeks

With $\varphi$ the standard normal PDF:

Greek Formula Meaning
Delta $s,e^{-qT} N(s,d_1)$ Price change per $1 move in spot
Gamma $\dfrac{e^{-qT}\varphi(d_1)}{S\sigma\sqrt{T}}$ Change in delta per $1 move in spot
Vega $S e^{-qT}\varphi(d_1)\sqrt{T}$ Price change per 1 point of volatility
Theta $-\dfrac{S e^{-qT}\varphi(d_1)\sigma}{2\sqrt{T}} - s,rKe^{-rT}N(s,d_2) + s,qSe^{-qT}N(s,d_1)$ Price change per day
Rho $s,KTe^{-rT}N(s,d_2)$ Price change per 1 point of interest rate

Implied volatility

There is no closed form for $\sigma$ given a price, so it is found numerically. Newton-Raphson uses vega as the derivative and converges in a few steps near the money. Every step also keeps a bracket known to contain the answer, and falls back to bisection when a Newton step would leave it, which guarantees convergence for deep in- or out-of-the-money options where vega is tiny. Prices outside the no-arbitrage range are rejected, since no volatility can produce them.

Use as a library

from bs_pricer import bs_greeks, bs_price, implied_vol

bs_price(100, 100, 1, 0.05, 0.2, option_type="call")   # 10.4506
bs_greeks(100, 100, 1, 0.05, 0.2, option_type="call")  # {"delta": 0.6368, ...}
implied_vol(10.4506, 100, 100, 1, 0.05)                # 0.2000

# Arrays broadcast: a 2 x 3 grid of prices in one call
import numpy as np
bs_price(np.array([90, 100, 110]), 100, 1, 0.05, np.array([[0.1], [0.2]]))

Run locally

git clone https://github.com/FinnBrennan/black-scholes-pricer.git
cd black-scholes-pricer
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
streamlit run app.py

Run the tests:

pip install pytest
python3 -m pytest

Project structure

black-scholes-pricer/
├── bs_pricer/          pricing engine (with no UI dependencies)
│   ├── pricer.py       bs_price, prob_itm, shared input validation
│   ├── greeks.py       bs_greeks
│   └── iv.py           implied_vol
├── tests/              pytest suite for bs_pricer
├── app.py              Streamlit front end
├── charts.py           Plotly sensitivity and Greek charts
├── heatmap.py          Plotly price heatmaps
└── requirements.txt

v1 to v2: Learnings and Changes

I built v1 in June of 2026 as one of my first personal projects. Re-approaching the project 5 months later, I have learnt a lot more about Python as well as the maths behind Black-Scholes. Thus I noticed significant ways in which I would change how I approached the project, so version 2 has become a complete rewrite rather than a patch or a few small changes. I have also extended the scope to include Greeks and Implied Volatility.

  • Actually understanding the maths rather than just the formula. In v1 I implemented Black-Scholes mainly by just copying the formula. For v2 I properly understood what each term means and how they interact: $N(d_2)$ as the risk-neutral probability of finishing in the money, why $d_2 = d_1 - \sigma\sqrt{T}$, and how the Greeks fall out of the same terms. That is what made adding Greeks and implied volatility straightforward.
  • Streamlit's execution model. v1 fought Streamlit with Calculate and Reset buttons and a session-state flag to keep results on screen between reruns. Once I understood that Streamlit reruns the whole script on every input change, all of that could be removed: prices now update live, and app.py went from 440 lines to 189.
  • Separating the engine from the UI. Inputs were only validated in the app rather than the engine, and my chart functions took 13 arguments. The pricing code is now its own package, validates its own inputs, and works on NumPy arrays, so charts and heatmaps are single broadcast calls instead of slow and messy nested loops.
  • Testing properly. v1 only had one test checking one value. v2 tests against properties that must hold, such as put-call parity and Greeks agreeing with bump-and-reprice finite differences, which catch mistakes that the previous version wouldn't.
  • Interactive charts. Static Matplotlib images were replaced with Plotly charts and heatmaps you can hover, zoom and pan.
  • New features: all five Greeks, an implied volatility solver, and a Greek-vs-spot chart for each Greek.

More in-depth details of my changes are in CHANGELOG.md.

Acknowledgements

My UI design was inspired by the site: testfol.io. I used claude for the latex code used in the maths section of this readme.

Metadata

Release files for finn-bs-pricer 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for finn-bs-pricer 2.0.0
File Size Uploaded Provenance Actions
finn_bs_pricer-2.0.0.tar.gz 9.3 kB Without provenance Details for finn_bs_pricer-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for finn-bs-pricer 2.0.0
File Interpreter ABI Platform Actions
finn_bs_pricer-2.0.0-py3-none-any.whl Python 3 none any Details for finn_bs_pricer-2.0.0-py3-none-any.whl

Total release size: 17.3 kB

Release files / finn_bs_pricer-2.0.0.tar.gz

Download URL finn_bs_pricer-2.0.0.tar.gz
Size 9.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7b3fd9f07dae8ed3459368402c7d4a597ec3a7b5fa29a5520ee97418eca2ff84
BLAKE2b-256 checksum
How to use checksums
f4d8d0a644608edeffc59cdca0d3beef3d612ff08d773306acbd2ceb59e56259
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / finn_bs_pricer-2.0.0-py3-none-any.whl

Download URL finn_bs_pricer-2.0.0-py3-none-any.whl
Size 8.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aaa967ee9b98402ca88d09dad0fc8e16546c11816034a614d241358f5110f685
BLAKE2b-256 checksum
How to use checksums
fcaf84bb8a96607c6a35d1d4a4621f9b1f00625e2487558ff15a86563110162d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for finn-bs-pricer 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page