Fast and vectorised pricer and implied volatility fitters for Black-Scholes and Merton models
Project description
VanillaOptionPricers
Fast and vectorized option pricers and implied volatility fitters for Black-Scholes and Merton models
VanillaOptionPricers is a high-performance Python package that provides fast, vectorized implementations of option pricing models and implied volatility calculations. Built with Numba for optimal performance, this package is designed for quantitative analysts, traders, and researchers who need efficient option pricing capabilities.
Key Features
- High Performance: Vectorized implementations using Numba for maximum speed
- Multiple Models: Support for Black-Scholes-Merton and Bachelier normal models
- Implied Volatility: Fast and robust implied volatility solvers
- Option Types: Support for vanilla calls, puts, and inverse options
- Minimal Dependencies: Lightweight with core dependencies on NumPy and Numba only
- Easy Integration: Simple API for seamless integration into existing workflows
Installation
PyPI Installation
pip install vanilla-option-pricers
Upgrade to Latest Version
pip install --upgrade vanilla-option-pricers
Requirements
Core Dependencies
python >= 3.8, < 3.11numba >= 0.59.0numpy >= 1.26.4
The package maintains minimal dependencies on higher-level packages, ensuring fast installation and reduced compatibility issues.
Supported Option Types
VanillaOptionPricers supports the following option types (passed as string parameters):
| Option Type | String Code | Description |
|---|---|---|
| Call | 'C' |
Standard call option |
| Put | 'P' |
Standard put option |
| Inverse Call | 'IC' |
Inverse call option |
| Inverse Put | 'IP' |
Inverse put option |
Quick Start
Basic Option Pricing
import numpy as np
from vanilla_option_pricers import black_scholes_price, implied_volatility
# Define option parameters
spot = 100.0 # Current underlying price
strike = 105.0 # Strike price
time_to_expiry = 0.25 # Time to expiration (in years)
risk_free_rate = 0.05 # Risk-free interest rate
volatility = 0.20 # Volatility
option_type = 'C' # Call option
# Calculate option price
option_price = black_scholes_price(
spot=spot,
strike=strike,
time_to_expiry=time_to_expiry,
risk_free_rate=risk_free_rate,
volatility=volatility,
option_type=option_type
)
print(f"Option Price: ${option_price:.4f}")
Vectorized Calculations
import numpy as np
from vanilla_option_pricers import compute_bsm_vanilla_price_vector
# Vectorized pricing for multiple strikes
forwards = np.array([95, 100, 105, 110])
strikes = np.array([100, 100, 100, 100])
vols = np.array([0.15, 0.20, 0.25, 0.30])
option_prices = compute_bsm_vanilla_price_vector(
forward=forwards,
strike=strikes,
ttm=0.25,
vol=vols,
option_type='C'
)
print("Vectorized Option Prices:", option_prices)
Performance Benefits
VanillaOptionPricers leverages Numba's JIT compilation to achieve:
- Vectorization: Process arrays of parameters efficiently
- Speed: Orders of magnitude faster than pure Python implementations
- Memory Efficiency: Optimized memory usage for large-scale calculations
- Numerical Stability: Robust implementations with proper handling of edge cases
API Documentation
Core Functions
black_scholes_price(spot, strike, time_to_expiry, risk_free_rate, volatility, option_type)
Calculate Black-Scholes option price.
Parameters:
spot(float/array): Current underlying pricestrike(float/array): Strike pricetime_to_expiry(float/array): Time to expiration in yearsrisk_free_rate(float/array): Risk-free interest ratevolatility(float/array): Volatility (annualized)option_type(str): Option type ('C', 'P', 'IC', 'IP')
Returns:
float/array: Option price(s)
implied_volatility(market_price, spot, strike, time_to_expiry, risk_free_rate, option_type)
Calculate implied volatility from market price.
Parameters:
market_price(float/array): Observed market pricespot(float/array): Current underlying pricestrike(float/array): Strike pricetime_to_expiry(float/array): Time to expiration in yearsrisk_free_rate(float/array): Risk-free interest rateoption_type(str): Option type ('C', 'P', 'IC', 'IP')
Returns:
float/array: Implied volatility(ies)
Use Cases
VanillaOptionPricers is ideal for:
- Quantitative Research: Academic research requiring fast option pricing
- Trading Systems: Real-time option pricing in trading applications
- Risk Management: Portfolio risk calculations and scenario analysis
- Market Making: High-frequency option pricing and implied volatility calculations
- Financial Education: Teaching option pricing concepts with efficient implementations
Contributing
We welcome contributions! Please feel free to submit issues, feature requests, or pull requests.
Development Setup
git clone https://github.com/ArturSepp/VanillaOptionPricers.git
cd VanillaOptionPricers
pip install -e .
License
This project is licensed under the MIT License - see the LICENSE file for details.
BibTeX Citation
If you use VanillaOptionPricers in your research, please cite it as:
@software{sepp2024vanillaoptionpricers,
title={VanillaOptionPricers: Fast and vectorized option pricers and implied volatility fitters for Black-Scholes and Merton models},
author={Sepp, Artur},
year={2024},
url={https://github.com/ArturSepp/VanillaOptionPricers},
note={Python package for high-performance option pricing}
}
Project details
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 vanilla_option_pricers-1.2.2.tar.gz.
File metadata
- Download URL: vanilla_option_pricers-1.2.2.tar.gz
- Upload date:
- Size: 54.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a4041d2e698b4a8420ce58368451efe33b165d85c1655b4cb8caaedd12fb1dd
|
|
| MD5 |
1b016e0fd9ea22832bafaea0162d9a66
|
|
| BLAKE2b-256 |
da08da1593dff9aac757f68b9fa4c15ae8c3dc2d90c998bc78ca8eff1b39d814
|
File details
Details for the file vanilla_option_pricers-1.2.2-py3-none-any.whl.
File metadata
- Download URL: vanilla_option_pricers-1.2.2-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d563cbb1acf208ec33bf9cabe1e1f2ee44027583acd5fbfd4877150710711ba
|
|
| MD5 |
db0c32410231ad3f67567e81e2950408
|
|
| BLAKE2b-256 |
e70f5226160577b987f052fba727db81f20fef8f4a8043041e64ba7e78907e83
|