
High-performance Black-Scholes calculations for dataframes.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
Options-dataframes is a high-performance Python package designed for efficient Black-Scholes calculations on large option datasets. Leveraging the power of Polars, a high-performance data processing library, this package provides a fast and scalable solution for quantitative analysts and financial engineers.
-
Efficient Black-Scholes Calculations: Calculate option prices, implied volatilities, and greeks (delta, gamma, vega, theta, rho) with optimized algorithms.
-
Pandas and Polars Compatibility: Seamlessly integrate with both Pandas and Polars dataframes, offering flexibility in data handling.
-
Dependency Tree Optimization: Avoid redundant calculations by intelligently managing dependencies, ensuring maximum performance.
-
Robust Root-Finding Algorithms: Employ Brent and Jaeckel's algorithms for accurate and efficient implied volatility calculations.
- Quantitative analysts
- Financial engineers
- Researchers
- Traders
- Speed: Experience significantly faster Black-Scholes calculations compared to traditional Python implementations.
- Scalability: Handle large datasets without performance degradation.
- Ease of Use: A straightforward API that integrates seamlessly into your existing workflows.
- Accuracy: Rely on robust algorithms for accurate results.
- Performance Optimization: Benefit from intelligent dependency management and optimized calculations.
Here is an example of how to use the package on the included test dataframe.
import options_dataframes as odf
# Loads included test dataframe, including prices
test_option_data = odf.test_option_data(length=10_000)
# Calculates option implied volatilities
test_option_data = odf.with_black_scholes(test_option_data, method="brent")
# Calculates requested option greeks
test_option_data = odf.with_black_scholes_greeks(
test_option_data,
greeks=[odf.Greeks.Delta, odf.Greeks.Theta],
)
odf.show(test_option_data, max_rows=5, random=True)
For more examples, please refer to the Documentation
The package is available in PyPI. To get started, follow the instructions below:
-
Install the package in a virtual environment
source my_env/bin/activate pip install options-dataframes
or using poetry
poetry install options-dataframes
-
Import and use the package
import options_dataframes as odf
In the below by BS inputs we mean the following columns:
strike
expiration
option_type
risk_free_rate
underlying_price
and either underlying_price
or implied_volatility
. The inputs will be denoted in mathematical formulas as:
-
$S$ -underlying_price
-
$T$ -expiration
-
$r$ -risk_free_rate
-
$K$ -strike
-
$t$ -time_to_expiration
-
$\sigma$ -implied_volatility
-
$P$ -option_price
-
odf.with_black_scholes
- Validates input dataframe contains necessary BS inputs.
- Calculates option prices from BS inputs or implied volatilities, if price is given.
- Appends respective columns
option_price
orimplied_volatility
to the original dataframe.
-
odf.with_black_scholes_greeks
- Validates input dataframe contains necessary BS inputs, if
implied_volatility
is not present calculates it. - Calculates greeks with optimized algorithms.
- Avalible greeks:
- First-order:
- Delta -
$\frac{\partial P}{\partial S}$ - Rho -
$\frac{\partial P}{\partial r}$ - Vega -
$\frac{\partial P}{\partial \sigma}$ - Theta -
$\frac{\partial P}{\partial t}$ - Dual Delta -
$\frac{\partial P}{\partial K}$
- Delta -
- Second-order:
- Gamma -
$\frac{\partial^2 P}{\partial S^2}$ - Vanna -
$\frac{\partial^2 P}{\partial \sigma \partial S}$ - Vomma -
$\frac{\partial^2 P}{\partial \sigma^2}$
- Gamma -
- First-order:
- Appends respective columns
delta
,gamma
,vega
,theta
,rho
to the original dataframe.
- Validates input dataframe contains necessary BS inputs, if
Seamlessly integrate with both Pandas and Polars dataframes, offering flexibility in data handling.
All calculations are performed natively in Rust using Polars and are highly optimized for performance. The Python package provides a dataframe wrapper for both Pandas and Polars dataframes.
All functions with dataframe inputs are agnostic to the dataframe type, and can be used with both.
To avoid redundant calculations by intelligently managing dependencies, ensuring maximum performance. Partial calculations that would be used ex. for both delta and theta are only performed once.
Example dependency tree for call and put options price, delta and gamma:
graph TD;
D --> DK;
d_m --> N_mm;
d_m --> N_pm;
d_p --> d_m;
d_p --> N_mp;
d_p --> N_pp;
d_p --> N_prime;
DK --> C;
DK --> P;
K --> DK;
K --> log_money;
log_money --> d_p;
N_mm --> P;
N_mp --> P;
N_pm --> C;
N_pp --> C;
N_pp --> Delta_C;
N_pp --> Delta_P;
N_prime --> Gamma;
r --> D;
S --> C;
S --> Gamma;
S --> log_money;
S --> P;
sigma --> d_m;
sigma --> d_p;
sigma --> Gamma;
sigma --> sigma_sq;
sigma_sq --> d_p;
sqrt_tau --> d_p;
sqrt_tau --> Gamma;
t --> tau;
T --> tau;
tau --> d_m;
tau --> d_p;
tau --> D;
tau --> sqrt_tau;
For more information, please refer to the documentation.
Employ Rust-implemented algorithms for accurate and efficient implied volatility calculation. Algorithms include:
General purpose bracketed algorithm for finding the root of a continous function.
Algorithm specifically optimized for Black-Scholes implied volatility calculations.
- Create Development README.
- Dummy Rust-Python interop package.
- Calculation of BS price (no dependency tree).
- Test data included in package.
- Set up CI pipeline.
- Calculation of IV.
- Brent's method (use Rust implementation).
- Jaeckel's rational algorithm (use implied-vol Rust crate).
- Performance comparison.
- Implementation of dependency tree for BS and IV.
- Calculation of greeks.
- Delta.
- Gamma.
- Vega.
- Theta.
- Rho.
- Dual Delta.
- Vanna.
- Vomma.
- Release to PyPI.
- Internal IV implementation.
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.