A financial options pricing and analysis library.
Project description
OptPricing: A Quantitative Finance Library for Derivative Pricing and Analysis
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: Dupire's Equation
-
Pricing Engines: Provides a suite of numerical methods, allowing for technique comparison and validation:
- Analytic closed-form solutions
- Numerical integration and FFT-based pricing via characteristic functions
- Finite difference (PDE) solver using a Crank-Nicolson scheme
- Binomial and trinomial tree methods (CRR, TOPM, Leisen-Reimer) for European and American options
- High-performance Monte Carlo engine for European and American options, accelerated with
numba, featuring variance reduction techniques (e.g., antithetic variates, control variates, importance sampling)
-
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 is designed for a straightforward installation using pip and is compatible with Python 3.10 and higher.
1. Install the Library
pip install optpricing
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, retrieves the current dividend rate, calculates the implied risk-free rate from at-the-money contracts, and prices the contract with Heston’s model using its default pricing technique (FFT):
optpricing price --ticker AAPL --strike 630 --maturity 2025-12-19 --model Heston --param "rho=-0.7" --param "vol_of_vol=0.5"
To price the same contract as an American Option use:
optpricing price -t AAPL -k 210 -T 2025-12-19 --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, interact with a pricing calculator featuring 15 models and 10 techniques.
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.
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 optpricing-2.3.4.tar.gz.
File metadata
- Download URL: optpricing-2.3.4.tar.gz
- Upload date:
- Size: 20.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4496d7ef7e7048db6934f53638f330b6a4e86711e3d15ef23cb9861fbd8f6853
|
|
| MD5 |
80eee337667c6319a4508b129b05f624
|
|
| BLAKE2b-256 |
20834c696b7f2cbec35974848223037d05eabc4a9cc36630f73ba5be710357bb
|
Provenance
The following attestation bundles were made for optpricing-2.3.4.tar.gz:
Publisher:
publish.yml on Diljit22/optpricing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
optpricing-2.3.4.tar.gz -
Subject digest:
4496d7ef7e7048db6934f53638f330b6a4e86711e3d15ef23cb9861fbd8f6853 - Sigstore transparency entry: 297378935
- Sigstore integration time:
-
Permalink:
Diljit22/optpricing@daefa6a7afd0bf62797a2585625dac39cfc153c6 -
Branch / Tag:
refs/tags/v2.3.4 - Owner: https://github.com/Diljit22
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@daefa6a7afd0bf62797a2585625dac39cfc153c6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file optpricing-2.3.4-py3-none-any.whl.
File metadata
- Download URL: optpricing-2.3.4-py3-none-any.whl
- Upload date:
- Size: 128.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7d1e206136a276f389f24bc52a0f92e98c65f66d51beddf25e96fc36e65e73b
|
|
| MD5 |
f6d154c79c8845739261061ff7efac8d
|
|
| BLAKE2b-256 |
ff305045e31ea632e6c09d75d3c9af2c84998283e37ebcff40b8eae64a3f4825
|
Provenance
The following attestation bundles were made for optpricing-2.3.4-py3-none-any.whl:
Publisher:
publish.yml on Diljit22/optpricing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
optpricing-2.3.4-py3-none-any.whl -
Subject digest:
d7d1e206136a276f389f24bc52a0f92e98c65f66d51beddf25e96fc36e65e73b - Sigstore transparency entry: 297378959
- Sigstore integration time:
-
Permalink:
Diljit22/optpricing@daefa6a7afd0bf62797a2585625dac39cfc153c6 -
Branch / Tag:
refs/tags/v2.3.4 - Owner: https://github.com/Diljit22
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@daefa6a7afd0bf62797a2585625dac39cfc153c6 -
Trigger Event:
push
-
Statement type: