Skip to main content

Polar plugin Option Pricing

Overview

Polars plugin exposing rust crate option-pricing.

Install

Commands:

# ------- install from pypi/artifactory
pip install polars_plugin_option_pricing

Use

Black-Scholes

Calculate Call & Put Option price and greeks with BlackScholes formula:

In short:

import polars_plugin_option_pricing as m

# black scholes
df = df.with_columns(
    output_bs=m.black_scholes(
        "is_call", 
        "spot", 
        "strike", 
        "mat", 
        "vol", 
        "rate", 
        "div"
    ),
).drop(["is_call"]).unnest("output_bs")

Implied Vol

Calculate implied volatility for call options:

In short:

import polars_plugin_option_pricing as m

# implied vol
df = df.with_columns(
    iv_output=m.implied_vol(
        "price",
        "spot",
        "strike",
        "mat",
        "rate",
        "div",
        iter=10,
        prec=1e-7,
        # method="Newton",
        method="Halley",
    )
).unnest("iv_output")

Install dev mode

Commands:

# ------- install from repo
# clone
git clone https://github.com/oscar6echo/polars-plugin-option-pricing.git
cd polars-plugin-option-pricing

# fast compile, slow exec
maturin develop
# slow compile, fast exec
maturin develop --release


# alternative
pip install -v -e .

# watch 
cargo watch --watch ./src -- maturin develop

Build

Commands:

# ------- build native wheel
maturin build --sdist --release --out dist

# ------- build manylinux wheel
# install zig
pip install maturin[zig]

maturin build --release --target x86_64-unknown-linux-gnu --zig --out dist


#######################################################
# NOTE
# build wheel win specific
# edit src/lib.rs and comment PolarsAllocator 
# ref https://github.com/PyO3/maturin/discussions/2297
#######################################################

# ------- build windows wheel - 1st method
# debian & co
sudo apt-get install mingw-w64

# check compilation
maturin build --profile dev --target x86_64-pc-windows-gnu --out dist

maturin build --release --target x86_64-pc-windows-gnu --out dist

# ------- build windows wheel - 2nd method
# docker
docker build -t builder-win:local -f ./win.Dockerfile .
docker run --rm -v "$(pwd)":/io builder-win:local

This produces wheels for linux and windows:

❯ ls dist
polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl
polars_plugin_option_pricing-0.1.0-cp38-abi3-win_amd64.whl
polars_plugin_option_pricing-0.1.0.tar.gz

Publish

Commands:

# prerequisite
pip install -U twine

twine check dist/*

# assuming .pypirc configured
# for linux only manylinux: the others will be refused
twine upload dist/*.tar.gz
twine upload dist/*manylinux*
twine upload dist/*win_amd64*

Ref

Metadata

Release files for polars-plugin-option-pricing 0.1.0

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

Source distribution (sdist)

Source distribution for polars-plugin-option-pricing 0.1.0
File Size Uploaded
polars_plugin_option_pricing-0.1.0.tar.gz 23.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for polars-plugin-option-pricing 0.1.0
File Interpreter ABI Platform
polars_plugin_option_pricing-0.1.0-cp38-abi3-win_amd64.whl CPython 3.8 abi3 Windows x86-64 Details
polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl CPython 3.8 abi3 Linux glibc 2.34+ x86-64 Details
polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 abi3 Linux glibc 2.17+ x86-64 Details

Total release size: 10.6 MB

Release files / polars_plugin_option_pricing-0.1.0.tar.gz

Download URL polars_plugin_option_pricing-0.1.0.tar.gz
Size 23.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e84663affa9591ddd5596589d6b5a0847e5f083cf184851e5fbac8f37d8148fe
BLAKE2b-256 checksum
How to use checksums
a8eca1c76361274824164a178dc02a3a1b1ccbfbaa63feac71ad042ec55f1d26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / polars_plugin_option_pricing-0.1.0-cp38-abi3-win_amd64.whl

Download URL polars_plugin_option_pricing-0.1.0-cp38-abi3-win_amd64.whl
Size 3.1 MB
Tags CPython 3.8 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
0a70d09d1af3b8fdc0288fc17a98fe01823ccc1477474593411363552389af73
BLAKE2b-256 checksum
How to use checksums
09dbb4b97c42d2c912dec78b45eefc7cb794e012676c128742618e88f29721df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl

Download URL polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl
Size 3.7 MB
Tags CPython 3.8 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
e8ac7c1a9f2812ad78098d2b4b850d744635361d43a318af1ad63247bd21858e
BLAKE2b-256 checksum
How to use checksums
2ea04e10a83d7cdbbbac132b6ac7353ee295301a55db4a2598ba49cb1f7fb99c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.7 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
f0aa581c8a0b469ca7e196cee26601d2f8e1633ef8cc1b2aeb1d9bca94507097
BLAKE2b-256 checksum
How to use checksums
5a14817f48551d4e4d32953ac5e9da8c7958b88f2713d29eaee65c7c915856c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

4 release files

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