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
- Polars plugins tutorial by Marco Gorelli -> Very useful !
- Github issue Suggestion: Plugin full example with input of n cols and output of m cols
- repo oscar6echo/pyo3-option-pricing using the same underlying crate, but vastly less efficient for batch pricing.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file polars_plugin_option_pricing-0.1.0.tar.gz
.
File metadata
- Download URL: polars_plugin_option_pricing-0.1.0.tar.gz
- Upload date:
- Size: 23.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e84663affa9591ddd5596589d6b5a0847e5f083cf184851e5fbac8f37d8148fe |
|
MD5 | a5a56749ab2cc5c42b0b76adace61333 |
|
BLAKE2b-256 | a8eca1c76361274824164a178dc02a3a1b1ccbfbaa63feac71ad042ec55f1d26 |
File details
Details for the file polars_plugin_option_pricing-0.1.0-cp38-abi3-win_amd64.whl
.
File metadata
- Download URL: polars_plugin_option_pricing-0.1.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a70d09d1af3b8fdc0288fc17a98fe01823ccc1477474593411363552389af73 |
|
MD5 | 7aaf76b2cffa878bf226e3f908d3e2a4 |
|
BLAKE2b-256 | 09dbb4b97c42d2c912dec78b45eefc7cb794e012676c128742618e88f29721df |
File details
Details for the file polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl
.
File metadata
- Download URL: polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8ac7c1a9f2812ad78098d2b4b850d744635361d43a318af1ad63247bd21858e |
|
MD5 | a447160c52ff8af789f62b654e96acd8 |
|
BLAKE2b-256 | 2ea04e10a83d7cdbbbac132b6ac7353ee295301a55db4a2598ba49cb1f7fb99c |
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
- Download URL: polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0aa581c8a0b469ca7e196cee26601d2f8e1633ef8cc1b2aeb1d9bca94507097 |
|
MD5 | a5cbe222a5c9f59c928033e49f3b785e |
|
BLAKE2b-256 | 5a14817f48551d4e4d32953ac5e9da8c7958b88f2713d29eaee65c7c915856c2 |