Python package for options pricing and Greeks computation
Project description
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)
- Implied volatility — Newton-Raphson, bisection, and Brent solvers with arbitrage-bounds checking
- 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
- Barrier options — continuous and discrete monitoring, knock-in/knock-out, rebates (at-hit and at-expiry)
- 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
Beta feature — barrier options
Barrier option pricing is currently available as a pre-release. To install:
pip install --pre -U derivatives-pricing
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, end_time=1.0)
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.BSM,
)
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
Roadmap
Planned: stochastic volatility models.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file derivatives_pricing-0.2.0b1.tar.gz.
File metadata
- Download URL: derivatives_pricing-0.2.0b1.tar.gz
- Upload date:
- Size: 229.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a6861b1f5bfd8c3ae02442fc77a0ccc5742aed279c5e30ea2b04c3e470d4c7a
|
|
| MD5 |
515bab64148cd18188d7372d2691356d
|
|
| BLAKE2b-256 |
64ffaca533cf40c2cfc38b1c42b5d6d5b0126fafb10dca2c30d5ca5295b22973
|
Provenance
The following attestation bundles were made for derivatives_pricing-0.2.0b1.tar.gz:
Publisher:
release.yml on jsidhu06/derivatives-pricing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
derivatives_pricing-0.2.0b1.tar.gz -
Subject digest:
5a6861b1f5bfd8c3ae02442fc77a0ccc5742aed279c5e30ea2b04c3e470d4c7a - Sigstore transparency entry: 1361700479
- Sigstore integration time:
-
Permalink:
jsidhu06/derivatives-pricing@9d2ab95427c59f5883ac3842240424a54e480a6c -
Branch / Tag:
refs/tags/v0.2.0b1 - Owner: https://github.com/jsidhu06
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9d2ab95427c59f5883ac3842240424a54e480a6c -
Trigger Event:
push
-
Statement type:
File details
Details for the file derivatives_pricing-0.2.0b1-py3-none-any.whl.
File metadata
- Download URL: derivatives_pricing-0.2.0b1-py3-none-any.whl
- Upload date:
- Size: 118.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1a5709222b26ab6fa5198a77e8da1204a6e297232fb8e48e5c91e6c33893532
|
|
| MD5 |
c56b2bffeb445f71d2d7581682b89a21
|
|
| BLAKE2b-256 |
dad426fccf413746f086b1b6f592e2585833bceb5fbd31fccfe8b8bcfe52876c
|
Provenance
The following attestation bundles were made for derivatives_pricing-0.2.0b1-py3-none-any.whl:
Publisher:
release.yml on jsidhu06/derivatives-pricing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
derivatives_pricing-0.2.0b1-py3-none-any.whl -
Subject digest:
e1a5709222b26ab6fa5198a77e8da1204a6e297232fb8e48e5c91e6c33893532 - Sigstore transparency entry: 1361700491
- Sigstore integration time:
-
Permalink:
jsidhu06/derivatives-pricing@9d2ab95427c59f5883ac3842240424a54e480a6c -
Branch / Tag:
refs/tags/v0.2.0b1 - Owner: https://github.com/jsidhu06
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9d2ab95427c59f5883ac3842240424a54e480a6c -
Trigger Event:
push
-
Statement type: