# Polar plugin Option Pricing
## Overview
[Polars plugin](https://docs.pola.rs/user-guide/expressions/plugins/) exposing rust crate [option-pricing](https://crates.io/crates/option-pricing).
## Install
Commands:
```sh
# ------- install from pypi/artifactory
pip install polars_plugin_option_pricing
```
## Use
### Black-Scholes
Calculate Call & Put Option price and greeks with [BlackScholes formula](https://en.wikipedia.org/wiki/Black%E2%80%93Scholes_model):
+ [run-bs.py](./test/run-bs.py)
+ [run-bs.ipynbpy](./test/run-bs.ipynb)
In short:
```py
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](https://en.wikipedia.org/wiki/Implied_volatility) for call options:
+ [run-iv.py](./test/run-iv.py)
+ [run-iv.ipynbpy](./test/run-iv.ipynb)
In short:
```py
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:
```sh
# ------- 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:
```sh
# ------- 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:
```sh
❯ 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:
```sh
# 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](https://marcogorelli.github.io/polars-plugins-tutorial/) by Marco Gorelli -> Very useful !
+ Github issue [Suggestion: Plugin full example with input of n cols and output of m cols](https://github.com/MarcoGorelli/polars-plugins-tutorial/issues/58)
+ repo [oscar6echo/pyo3-option-pricing](https://github.com/oscar6echo/pyo3-option-pricing) using the same underlying crate, but vastly less efficient for batch pricing.
Raw data
{
"_id": null,
"home_page": null,
"name": "polars-plugin-option-pricing",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "polars, plugin, blackscholes",
"author": null,
"author_email": "firstname lastname <author@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a8/ec/a1c76361274824164a178dc02a3a1b1ccbfbaa63feac71ad042ec55f1d26/polars_plugin_option_pricing-0.1.0.tar.gz",
"platform": null,
"description": "# Polar plugin Option Pricing\n\n## Overview\n\n[Polars plugin](https://docs.pola.rs/user-guide/expressions/plugins/) exposing rust crate [option-pricing](https://crates.io/crates/option-pricing).\n\n## Install\n\nCommands:\n\n```sh\n# ------- install from pypi/artifactory\npip install polars_plugin_option_pricing\n```\n\n## Use\n\n### Black-Scholes\n\nCalculate Call & Put Option price and greeks with [BlackScholes formula](https://en.wikipedia.org/wiki/Black%E2%80%93Scholes_model):\n\n+ [run-bs.py](./test/run-bs.py)\n+ [run-bs.ipynbpy](./test/run-bs.ipynb)\n\nIn short:\n\n```py\nimport polars_plugin_option_pricing as m\n\n# black scholes\ndf = df.with_columns(\n output_bs=m.black_scholes(\n \"is_call\", \n \"spot\", \n \"strike\", \n \"mat\", \n \"vol\", \n \"rate\", \n \"div\"\n ),\n).drop([\"is_call\"]).unnest(\"output_bs\")\n```\n\n### Implied Vol\n\nCalculate [implied volatility](https://en.wikipedia.org/wiki/Implied_volatility) for call options:\n\n+ [run-iv.py](./test/run-iv.py)\n+ [run-iv.ipynbpy](./test/run-iv.ipynb)\n\nIn short:\n\n```py\nimport polars_plugin_option_pricing as m\n\n# implied vol\ndf = df.with_columns(\n iv_output=m.implied_vol(\n \"price\",\n \"spot\",\n \"strike\",\n \"mat\",\n \"rate\",\n \"div\",\n iter=10,\n prec=1e-7,\n # method=\"Newton\",\n method=\"Halley\",\n )\n).unnest(\"iv_output\")\n```\n\n## Install dev mode\n\nCommands:\n\n```sh\n# ------- install from repo\n# clone\ngit clone https://github.com/oscar6echo/polars-plugin-option-pricing.git\ncd polars-plugin-option-pricing\n\n# fast compile, slow exec\nmaturin develop\n# slow compile, fast exec\nmaturin develop --release\n\n\n# alternative\npip install -v -e .\n\n# watch \ncargo watch --watch ./src -- maturin develop\n```\n\n## Build\n\nCommands:\n\n```sh\n# ------- build native wheel\nmaturin build --sdist --release --out dist\n\n# ------- build manylinux wheel\n# install zig\npip install maturin[zig]\n\nmaturin build --release --target x86_64-unknown-linux-gnu --zig --out dist\n\n\n#######################################################\n# NOTE\n# build wheel win specific\n# edit src/lib.rs and comment PolarsAllocator \n# ref https://github.com/PyO3/maturin/discussions/2297\n#######################################################\n\n# ------- build windows wheel - 1st method\n# debian & co\nsudo apt-get install mingw-w64\n\n# check compilation\nmaturin build --profile dev --target x86_64-pc-windows-gnu --out dist\n\nmaturin build --release --target x86_64-pc-windows-gnu --out dist\n\n# ------- build windows wheel - 2nd method\n# docker\ndocker build -t builder-win:local -f ./win.Dockerfile .\ndocker run --rm -v \"$(pwd)\":/io builder-win:local\n\n```\n\nThis produces wheels for linux and windows:\n\n```sh\n\u276f ls dist\npolars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl\npolars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl\npolars_plugin_option_pricing-0.1.0-cp38-abi3-win_amd64.whl\npolars_plugin_option_pricing-0.1.0.tar.gz\n```\n\n## Publish\n\nCommands:\n\n```sh\n# prerequisite\npip install -U twine\n\ntwine check dist/*\n\n# assuming .pypirc configured\n# for linux only manylinux: the others will be refused\ntwine upload dist/*.tar.gz\ntwine upload dist/*manylinux*\ntwine upload dist/*win_amd64*\n```\n\n## Ref\n\n+ [Polars plugins tutorial](https://marcogorelli.github.io/polars-plugins-tutorial/) by Marco Gorelli -> Very useful !\n+ Github issue [Suggestion: Plugin full example with input of n cols and output of m cols](https://github.com/MarcoGorelli/polars-plugins-tutorial/issues/58)\n+ repo [oscar6echo/pyo3-option-pricing](https://github.com/oscar6echo/pyo3-option-pricing) using the same underlying crate, but vastly less efficient for batch pricing.\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "black scholes and implied vol calc",
"version": "0.1.0",
"project_urls": {
"repository": "https://github.com/oscar6echo/polars-plugin-explo.git"
},
"split_keywords": [
"polars",
" plugin",
" blackscholes"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5a14817f48551d4e4d32953ac5e9da8c7958b88f2713d29eaee65c7c915856c2",
"md5": "a5cbe222a5c9f59c928033e49f3b785e",
"sha256": "f0aa581c8a0b469ca7e196cee26601d2f8e1633ef8cc1b2aeb1d9bca94507097"
},
"downloads": -1,
"filename": "polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
"has_sig": false,
"md5_digest": "a5cbe222a5c9f59c928033e49f3b785e",
"packagetype": "bdist_wheel",
"python_version": "cp38",
"requires_python": ">=3.10",
"size": 3706692,
"upload_time": "2024-11-12T21:43:08",
"upload_time_iso_8601": "2024-11-12T21:43:08.876238Z",
"url": "https://files.pythonhosted.org/packages/5a/14/817f48551d4e4d32953ac5e9da8c7958b88f2713d29eaee65c7c915856c2/polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2ea04e10a83d7cdbbbac132b6ac7353ee295301a55db4a2598ba49cb1f7fb99c",
"md5": "a447160c52ff8af789f62b654e96acd8",
"sha256": "e8ac7c1a9f2812ad78098d2b4b850d744635361d43a318af1ad63247bd21858e"
},
"downloads": -1,
"filename": "polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl",
"has_sig": false,
"md5_digest": "a447160c52ff8af789f62b654e96acd8",
"packagetype": "bdist_wheel",
"python_version": "cp38",
"requires_python": ">=3.10",
"size": 3682168,
"upload_time": "2024-11-12T21:43:11",
"upload_time_iso_8601": "2024-11-12T21:43:11.933818Z",
"url": "https://files.pythonhosted.org/packages/2e/a0/4e10a83d7cdbbbac132b6ac7353ee295301a55db4a2598ba49cb1f7fb99c/polars_plugin_option_pricing-0.1.0-cp38-abi3-manylinux_2_34_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "09dbb4b97c42d2c912dec78b45eefc7cb794e012676c128742618e88f29721df",
"md5": "7aaf76b2cffa878bf226e3f908d3e2a4",
"sha256": "0a70d09d1af3b8fdc0288fc17a98fe01823ccc1477474593411363552389af73"
},
"downloads": -1,
"filename": "polars_plugin_option_pricing-0.1.0-cp38-abi3-win_amd64.whl",
"has_sig": false,
"md5_digest": "7aaf76b2cffa878bf226e3f908d3e2a4",
"packagetype": "bdist_wheel",
"python_version": "cp38",
"requires_python": ">=3.10",
"size": 3141302,
"upload_time": "2024-11-12T21:43:26",
"upload_time_iso_8601": "2024-11-12T21:43:26.475084Z",
"url": "https://files.pythonhosted.org/packages/09/db/b4b97c42d2c912dec78b45eefc7cb794e012676c128742618e88f29721df/polars_plugin_option_pricing-0.1.0-cp38-abi3-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a8eca1c76361274824164a178dc02a3a1b1ccbfbaa63feac71ad042ec55f1d26",
"md5": "a5a56749ab2cc5c42b0b76adace61333",
"sha256": "e84663affa9591ddd5596589d6b5a0847e5f083cf184851e5fbac8f37d8148fe"
},
"downloads": -1,
"filename": "polars_plugin_option_pricing-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "a5a56749ab2cc5c42b0b76adace61333",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 23614,
"upload_time": "2024-11-12T21:42:56",
"upload_time_iso_8601": "2024-11-12T21:42:56.717209Z",
"url": "https://files.pythonhosted.org/packages/a8/ec/a1c76361274824164a178dc02a3a1b1ccbfbaa63feac71ad042ec55f1d26/polars_plugin_option_pricing-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-12 21:42:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "oscar6echo",
"github_project": "polars-plugin-explo",
"github_not_found": true,
"lcname": "polars-plugin-option-pricing"
}