Fast Black-Scholes implied volatility calculation exposed from Rust to Python.
Project description
rust-py-calc-iv
用 Rust 实现的 Black-Scholes 欧式看涨期权隐含波动率计算模块,通过 Python 扩展暴露给 Python 使用。
功能
- 支持单个欧式看涨期权 IV 计算。
- 支持批量输入六个
numpy.ndarray[float64],返回一个 IV 数组。 - 批量计算时释放 GIL。
- 波动率从
[1e-8, 10.0]开始搜索;如果 10 仍未夹住解,会自动向上扩展。 - 当期权价格低于或贴近理论下界时,返回
1e-8。 - 当输入非法或期权价格超过理论上界时,返回
NaN。
理论边界:
lower = max(S * exp(-qT) - K * exp(-rT), 0)
upper = S * exp(-qT)
安装与构建
uv sync
uv run maturin develop --release
使用
import numpy as np
import rust_py_calc_iv
iv = rust_py_calc_iv.implied_vol_call(
100.0, 100.0, 1.0, 0.03, 0.01, 8.827321225352122
)
ivs = rust_py_calc_iv.implied_vol_call_batch(
np.array([100.0, 100.0]),
np.array([100.0, 100.0]),
np.array([1.0, 1.0]),
np.array([0.03, 0.03]),
np.array([0.01, 0.01]),
np.array([8.827321225352122, 12.69400452623556]),
)
输入参数依次为:
S:现货价格K:行权价格T:剩余期限,单位为年r:无风险利率,小数q:股息率,小数market_price:期权价格
测试
uv run pytest
cargo test
cargo clippy --all-targets -- -D warnings
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
rust_py_calc_iv-0.1.1.tar.gz
(15.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rust_py_calc_iv-0.1.1.tar.gz.
File metadata
- Download URL: rust_py_calc_iv-0.1.1.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0072e6c94f7cbfbd1a07bfa81353bdf8405c4a0e699c13ba8dbf40d64356dc7
|
|
| MD5 |
2c09239d30033c900fa798e35d9137b8
|
|
| BLAKE2b-256 |
91abe2f901f094fb22946d702b2772724837e6587e5c9e7d8d17f3bc3f732f9b
|
File details
Details for the file rust_py_calc_iv-0.1.1-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: rust_py_calc_iv-0.1.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 149.2 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae2960d71432f8800b9147eabf22b969bf4ea8ed0d0ef2aca9392d87557b0854
|
|
| MD5 |
2d0a0e4fb8c7f2e718b68004a13a5e65
|
|
| BLAKE2b-256 |
1b7f8455e80ca2ae479fc676e2b3c357ea9a7995c38ccee7138153abfc9d9f8a
|