derivatives-pricing
A Python package for options pricing and Greeks computation, with a unified API across analytical, binomial tree, finite difference and Monte Carlo methods.
Built for teaching, research, and production-adjacent workflows.
Features
Pricing Coverage
| Vanilla | Asian | Barrier | Custom | |
|---|---|---|---|---|
| BSM | E | E | E | — |
| Binomial | E/A | E/A | E/A | E/A |
| PDE_FD | E/A | — | E/A | E/A |
| Monte Carlo | E/A | E/A | E/A | E/A |
E = European, A = American
Method details: BSM uses closed-form Black-Scholes-Merton; Binomial uses Cox-Ross-Rubinstein trees; PDE_FD supports implicit, explicit, and Crank-Nicolson finite difference schemes; Monte Carlo uses Longstaff-Schwartz for American-style exercise. Asian analytical pricing uses Turnbull-Wakeman (arithmetic) and Kemna-Vorst (geometric), with Hull averaging on binomial trees. Barrier pricing supports continuous and discrete monitoring, knock-in and knock-out structures, and rebates.
Additional Capabilities
- Greeks — analytical, tree, grid, pathwise, likelihood-ratio, and numerical bump-and-revalue (delta, gamma, vega, theta, rho). On a sloped curve
theta depends on the method: analytical and MC pathwise / likelihood-ratio theta use the zero
rates to maturity (as QuantLib's
BlackCalculator), tree and PDE theta use the short-end forward rates (as QuantLib's FD engines), and numerical theta slides the curve with the pricing date (bringing in the forward rate at maturity); a single convention is planned - Implied volatility — Newton-Raphson, bisection, and Brent solvers with arbitrage-bounds checking; one absolute vol tolerance for every method, and quotes whose vega is too small to determine the vol (far out of the money, near intrinsic) are flagged
well_determined=False; Newton by default for ANALYTICAL, Brent for the tree and PDE (no vega needed) - Stochastic processes — Geometric Brownian Motion, Jump Diffusion (Merton), Square-Root Diffusion (CIR)
- Discount curves — log-linear interpolation on arbitrary term structures; deterministic time-varying forward rate and dividend curves
- Discrete dividends — supported across all pricing methods, under two standard models:
ANALYTICALandBINOMIALuse the escrowed model (the spot less the PV of dividends to maturity follows GBM), whilePDE_FDandMONTE_CARLOdrop the spot by each cash amount on its ex-date. The two give different prices for the same inputs, so compare engines within a model, and the European control variate is rejected forPDE_FD/MONTE_CARLOwhen there are discrete dividends. Both models share QuantLib's forward: with a dividend yield as well, each dividend's PV is discounted atr - q - Control variates — European analytical control variates for American pricing variance reduction
- Custom payoffs — user-defined payoff functions via
PayoffSpec
Why derivatives-pricing?
- Consistent API across analytical, tree, finite difference, and Monte Carlo methods
- Designed for transparency and clarity of implementation
- Includes vanilla, Asian, barrier, and custom-payoff workflows behind the same facade
- Suitable for teaching, experimentation, research, and production-adjacent workflows
- Extensible architecture for new models and payoffs
Installation
Install from PyPI:
pip install derivatives-pricing
# or pip install derivatives-pricing[numba] for optional PDE_FD solver acceleration
For development:
pip install -r requirements/dev.txt
pip install -e . --no-deps
pip install -e ".[jupyter]" # optional, for running notebooks
Requires Python 3.10 – 3.13
Quick Start
import datetime as dt
import derivatives_pricing as dp
pricing_date = dt.datetime(2025, 1, 1)
maturity = dt.datetime(2025, 7, 1)
dc = dp.DiscountCurve.flat(rate=0.05)
md = dp.MarketData(
pricing_date=pricing_date,
discount_curve=dc,
currency="USD",
)
underlying = dp.UnderlyingData(
initial_value=100.0,
volatility=0.20,
market_data=md,
)
spec = dp.VanillaSpec(
option_type=dp.OptionType.CALL,
exercise_type=dp.ExerciseType.EUROPEAN,
strike=105.0,
maturity=maturity,
)
val = dp.OptionValuation(
underlying=underlying,
spec=spec,
pricing_method=dp.PricingMethod.ANALYTICAL,
)
print(f"{'PV:':<8} {val.present_value():>10.4f}")
print(f"{'Delta:':<8} {val.delta():>10.4f}")
Examples & Tutorials
The repo includes two companion directories:
examples/— concise notebooks showing how to call the public API for each feature (European and American vanilla options, Asians, barriers, Greeks, jump diffusion, discount curves).tutorials/— deeper walkthroughs that teach the theory behind each pricing method (BSM, binomial trees, finite differences, Monte Carlo, Asian averaging, barrier pricing). Tutorials may access private/internal classes for demonstration purposes.
Tests
pytest -q -n auto --runslow
Project Structure
src/derivatives_pricing/
├── enums.py # OptionType, ExerciseType, PricingMethod, …
├── exceptions.py # Custom exception hierarchy
├── market_environment.py # MarketData, CorrelationContext
├── rates.py # DiscountCurve (log-linear interpolation)
├── stochastic_processes.py # GBM, JDProcess, SRD, PathSimulation
├── utils.py # Day-count, forward price, put-call parity
├── valuation/
│ ├── asian_analytical.py # Turnbull-Wakeman, Kemna-Vorst
│ ├── barrier_analytical.py # Analytical barrier pricing
│ ├── binomial.py # Cox-Ross-Rubinstein tree
│ ├── bsm.py # Closed-form Black-Scholes-Merton
│ ├── contracts.py # VanillaSpec, BarrierSpec, PayoffSpec, AsianSpec
│ ├── core.py # OptionValuation facade, UnderlyingData
│ ├── implied_volatility.py # IV solver
│ ├── monte_carlo.py # Monte Carlo with Longstaff-Schwartz and barrier pricing
│ ├── params.py # MonteCarloParams, BinomialParams, PDEParams
│ └── pde.py # Finite difference (implicit, explicit, Crank-Nicolson, barriers)
tests/ # Test suite
examples/ # API usage notebooks
tutorials/ # Theory deep-dive notebooks
Found a bug or have a feature request? Open an issue.
Disclaimer
This pricing library is provided as-is. Users are responsible for independently verifying any results before relying on them.
License
This repository uses a dual-license model.
| Component | License | SPDX |
|---|---|---|
src/derivatives_pricing/ |
MIT | MIT |
examples/ |
MIT | MIT |
tutorials/ |
CC BY-NC-SA 4.0 | CC-BY-NC-SA-4.0 |
Library code and examples are released under the MIT License and may be freely used, modified, and redistributed.
The PyPI distribution contains the MIT-licensed library package. Tutorial materials are separately hosted in the GitHub repository and are not part of the published package.
Tutorial notebooks in tutorials/ are licensed under Creative Commons
Attribution-NonCommercial-ShareAlike 4.0 (CC BY-NC-SA 4.0). You may share and
adapt these materials for non-commercial purposes with attribution. See the
full license text
for details.
Metadata
Release files for derivatives-pricing 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| derivatives_pricing-0.3.0.tar.gz | 282.3 kB | With provenance | Details for derivatives_pricing-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| derivatives_pricing-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for derivatives_pricing-0.3.0-py3-none-any.whl |
Total release size: 421.8 kB
Release files / derivatives_pricing-0.3.0.tar.gz
| Download URL | derivatives_pricing-0.3.0.tar.gz |
|---|---|
| Size | 282.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d938ce15030f13a14a13362a765304adbc302f5e354aa53e8fd03fec83d83509
|
|
BLAKE2b-256 checksum How to use checksums |
7e6775396955012684e94fe9e2e3f275b0886d1e6dae0425c82516809aa462a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logRelease files / derivatives_pricing-0.3.0-py3-none-any.whl
| Download URL | derivatives_pricing-0.3.0-py3-none-any.whl |
|---|---|
| Size | 139.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af7b6a557976a4f780cdfe9930239a64b1a25f3370a30a84c61c3bf70731ee17
|
|
BLAKE2b-256 checksum How to use checksums |
a81b03088d062d393847439f3fd020783ab0bcffa8c1164af010e8b6d9f9f885
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logSecurity for derivatives-pricing 0.3.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for derivatives_pricing-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 18, 2026.
Transparency logA 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.