Skip to main content

OptPricing: A Quantitative Finance Library for Derivative Pricing and Analysis

CI Coverage Docs PyPI version Python 3.11+ Ruff License: MIT

Live dashboard · Documentation

optpricing is a Python library for pricing, calibrating, and analyzing financial derivatives. It is built with a focus on architectural clarity, model breadth, and practical usability through a robust API, command-line interface, and an interactive dashboard.

Diljit Singh LinkedIn


Core Features

  • Model Library: Implements a comprehensive set of models, including:

    • Stochastic Volatility: Heston, SABR
    • Jump-Diffusion: Merton, Bates, Kou, SABR with Jumps
    • Pure Levy Processes: Variance Gamma (VG), Normal Inverse Gaussian (NIG), CGMY, Hyperbolic
    • Interest Rate Models: Vasicek, Cox-Ingersoll-Ross (CIR), Put-Call Parity Implied Rate
    • Local Volatility: CEV, Dupire
  • Pricing Engines: Provides a suite of numerical methods, allowing for technique comparison and validation:

    • Analytic closed-form solutions
    • Characteristic-function pricing: COS (Fang–Oosterlee), numerical integration, and Carr–Madan FFT
    • Finite difference (PDE) solver using a Crank-Nicolson scheme
    • Binomial and trinomial tree methods (CRR, TOPM, Leisen-Reimer) for European and American Black–Scholes options
    • High-performance Monte Carlo engine for European and American options, accelerated with numba, with antithetic variates
  • Interfaces:

    • Programmatic API: Use the package as a Python library to build custom financial models in your scripts. Define options, stocks, rates, and models programmatically to compute prices and other metrics.
    • Command-Line Interface (CLI): A robust CLI for live pricing, data management, model calibration, and historical backtesting.
    • Interactive Dashboard (UI): A Streamlit application for visual analysis of option chains, implied volatility surfaces, and model calibrations.
  • Workflow Automation: High-level classes that orchestrate complex tasks like daily calibration runs and out-of-sample performance evaluation.


Quick Start

optpricing installs with pip (or uv) and supports Python 3.11 through 3.14.

1. Install the Library

pip install optpricing          # library + CLI
pip install "optpricing[ui]"    # also the Streamlit dashboard

2. Download Historical Data

Some models require historical data (e.g., for calibration). Download data for a ticker like SPY:

optpricing data download --ticker SPY

For more details, see the Getting Started Guide.

3. Use the CLI

Price an option directly from the terminal. The command below fetches the live option chain for AAPL and prices the contract with the spot, the 13-week T-bill rate, and the dividend yield implied by put-call parity. Heston has no closed form, so the default technique is COS (Fang–Oosterlee):

optpricing price --ticker AAPL --strike 630 --maturity 2027-06-18 --model Heston --param "rho=-0.7" --param "vol_of_vol=0.5"

The same contract as an American option uses Longstaff–Schwartz Monte Carlo. Lattice techniques price American Black–Scholes only:

optpricing price -t AAPL -k 630 -T 2027-06-18 --style american --model Heston --param "rho=-0.7" --param "vol_of_vol=0.5"

For more details, see the CLI Guide.

4. Launch the Dashboard

Visualize option chains and model outputs, and interact with a pricing calculator covering 12 models and 9 techniques (the full library exposes 17 pricing models plus parity/implied-rate models, and 10 techniques, including American Monte Carlo). Requires the ui extra.

optpricing dashboard

For more details, see the Dashboard Guide.

5. Use the Programmatic API

The most powerful way to use the package is via the API, which provides customization of nearly every aspect of pricing:

from optpricing import Option, OptionType, Rate, Stock, ZeroCouponBond
from optpricing.models import BSMModel, CIRModel, VasicekModel
from optpricing.techniques import ClosedFormTechnique

# Define an option, underlying and rate
option = Option(strike=105, maturity=1.0, option_type=OptionType.CALL)
stock = Stock(spot=100, dividend=0.01)
rate = Rate(rate=0.05)

# Choose a model and technique
bsm_model = BSMModel(params={"sigma": 0.20})
cf_technique = ClosedFormTechnique()

result = cf_technique.price(option, stock, bsm_model, rate)
print(f"The option price is: {result.price:.4f}")


delta = cf_technique.delta(option, stock, bsm_model, rate)
gamma = cf_technique.gamma(option, stock, bsm_model, rate)
vega = cf_technique.vega(option, stock, bsm_model, rate)

print(f"Delta: {delta:.4f}")
print(f"Gamma: {gamma:.4f}")
print(f"Vega:  {vega:.4f}")

target_price = 7.50
iv = cf_technique.implied_volatility(
    option, stock, bsm_model, rate, target_price=target_price
)
print(f"Implied volatility for price ${target_price:.2f}: {iv:.4%}")


# Zero Coupon Bond
bond = ZeroCouponBond(maturity=1.0)
r0_stock = Stock(spot=0.05)  # initial short rate
dummy_rate = Rate(rate=0.0)  # ignored by rate models

vasicek = VasicekModel(params={"kappa": 0.86, "theta": 0.09, "sigma": 0.02})
cir = CIRModel(params={"kappa": 0.86, "theta": 0.09, "sigma": 0.02})

p_vasi = cf_technique.price(bond, r0_stock, vasicek, dummy_rate).price
p_cir = cf_technique.price(bond, r0_stock, cir, dummy_rate).price

print(f"Vasicek ZCB Price: {p_vasi:.4f}")
print(f"CIR ZCB Price:     {p_cir:.4f}")

For more details, see the API Guide.


Documentation

The full documentation includes installation instructions, user guides, examples, and a complete API reference.

Guides

Contributing

Contributions are welcome; see CONTRIBUTING for details.

License

This project is licensed under the MIT License. See LICENSE for details.

Metadata

Release files for optpricing 3.0.1

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

Source distribution (sdist)

Source distribution for optpricing 3.0.1
File Size Uploaded Provenance Actions
optpricing-3.0.1.tar.gz 237.9 kB With provenance Details for optpricing-3.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for optpricing 3.0.1
File Interpreter ABI Platform Actions
optpricing-3.0.1-py3-none-any.whl Python 3 none any Details for optpricing-3.0.1-py3-none-any.whl

Total release size: 438.2 kB

Release files / optpricing-3.0.1.tar.gz

Download URL optpricing-3.0.1.tar.gz
Size 237.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ecb9c2e896480be4a600a37bddfe7c86910aacb69ee9c2a85fb379e77e085e93
BLAKE2b-256 checksum
How to use checksums
74caec9d6e09c44a9ec517df818ce770670e6602f8471e134be8883a9f1fa423
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 18, 2026.

Transparency log

Release files / optpricing-3.0.1-py3-none-any.whl

Download URL optpricing-3.0.1-py3-none-any.whl
Size 200.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f59fab75c212ca4195b13e7030b418e1fa013953ffce7344d65bb6fce693daa9
BLAKE2b-256 checksum
How to use checksums
ea486582055ef14762b67731a3b92791a1e76895bb8fe4824de7fd2409ba710c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 18, 2026.

Transparency log

Security for optpricing 3.0.1

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.

Select from 2 files

Attestation for optpricing-3.0.1.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 Nov 18, 2026.

Transparency log

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.

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