Skip to content

Latest commit

 

History

History
343 lines (264 loc) · 12 KB

README.md

File metadata and controls

343 lines (264 loc) · 12 KB

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

options-dataframes

High-performance Black-Scholes calculations for dataframes.
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Usage
  3. Getting Started
  4. Detailed Features Overview
  5. Roadmap
  6. Contributing
  7. License
  8. Acknowledgments

About The Project

Project Screenshot Placeholder

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.

Key Features

  • 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.

Target Audience

  • Quantitative analysts
  • Financial engineers
  • Researchers
  • Traders

Why Choose options-dataframes?

  • 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.

(back to top)

Usage

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

(back to top)

Getting Started

The package is available in PyPI. To get started, follow the instructions below:

  1. Install the package in a virtual environment

    source my_env/bin/activate
    pip install options-dataframes

    or using poetry

    poetry install options-dataframes
  2. Import and use the package

    import options_dataframes as odf

(back to top)

Detailed Features Overview

Black-Scholes Inputs

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

Black-Scholes Calculations

  • 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 or implied_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}$
      • 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}$
    • Appends respective columns delta, gamma, vega, theta, rho to the original dataframe.

Pandas and Polars Compatibility

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.

Dependency Tree Optimization

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;
Loading

For more information, please refer to the documentation.

Robust Root-Finding Algorithms

Employ Rust-implemented algorithms for accurate and efficient implied volatility calculation. Algorithms include:

Brent's method

General purpose bracketed algorithm for finding the root of a continous function.

Jaeckel's rational algorithm

Algorithm specifically optimized for Black-Scholes implied volatility calculations.

Roadmap

  • 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).

(back to top)

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Top contributors

contrib.rocks image

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Acknowledgments

(back to top)