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.2.tar.gz
(15.8 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.2.tar.gz.
File metadata
- Download URL: rust_py_calc_iv-0.1.2.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd4db96fd2ae71ab1fbdccdb49582ca0872895b3310501caaa0a478f96412bac
|
|
| MD5 |
8ada927d6ca8237ad865d378bbd50bc5
|
|
| BLAKE2b-256 |
ce31d4bf804e47bccc3c131e4cb3229df13c689758e7b7b2b9837916a29f05a3
|
File details
Details for the file rust_py_calc_iv-0.1.2-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: rust_py_calc_iv-0.1.2-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 149.8 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 |
1274922e804185fd83d7b3b56ad1f0bf0463e80e36cb55a856fd9b189b2679f6
|
|
| MD5 |
355acaab914b07f56b7879322c52494b
|
|
| BLAKE2b-256 |
665d593e020c01ab72fd6b22db3f3d3529d21248964ff35b2685ea1c5c03a5bc
|