Skip to main content

black scholes and implied vol calc

Project description

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

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

polars_plugin_option_pricing-0.1.0.tar.gz (23.6 kB view details)

Uploaded Source

Built Distributions

polars_plugin_option_pricing-0.1.0-cp38-abi3-win_amd64.whl (3.1 MB view details)

Uploaded CPython 3.8+ Windows x86-64

polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.34+ x86-64

polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.8+ manylinux: glibc 2.17+ x86-64

File details

Details for the file polars_plugin_option_pricing-0.1.0.tar.gz.

File metadata

File hashes

Hashes for polars_plugin_option_pricing-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e84663affa9591ddd5596589d6b5a0847e5f083cf184851e5fbac8f37d8148fe
MD5 a5a56749ab2cc5c42b0b76adace61333
BLAKE2b-256 a8eca1c76361274824164a178dc02a3a1b1ccbfbaa63feac71ad042ec55f1d26

See more details on using hashes here.

File details

Details for the file polars_plugin_option_pricing-0.1.0-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for polars_plugin_option_pricing-0.1.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 0a70d09d1af3b8fdc0288fc17a98fe01823ccc1477474593411363552389af73
MD5 7aaf76b2cffa878bf226e3f908d3e2a4
BLAKE2b-256 09dbb4b97c42d2c912dec78b45eefc7cb794e012676c128742618e88f29721df

See more details on using hashes here.

File details

Details for the file polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e8ac7c1a9f2812ad78098d2b4b850d744635361d43a318af1ad63247bd21858e
MD5 a447160c52ff8af789f62b654e96acd8
BLAKE2b-256 2ea04e10a83d7cdbbbac132b6ac7353ee295301a55db4a2598ba49cb1f7fb99c

See more details on using hashes here.

File details

Details for the file polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0aa581c8a0b469ca7e196cee26601d2f8e1633ef8cc1b2aeb1d9bca94507097
MD5 a5cbe222a5c9f59c928033e49f3b785e
BLAKE2b-256 5a14817f48551d4e4d32953ac5e9da8c7958b88f2713d29eaee65c7c915856c2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page