Skip to main content

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

Metadata

Release files for rust-py-calc-iv 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rust-py-calc-iv 0.1.2
File Size Uploaded Provenance Actions
rust_py_calc_iv-0.1.2.tar.gz 15.8 kB Without provenance Details for rust_py_calc_iv-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rust-py-calc-iv 0.1.2
File Interpreter ABI Platform Actions
rust_py_calc_iv-0.1.2-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for rust_py_calc_iv-0.1.2-cp311-cp311-win_amd64.whl

Total release size: 165.6 kB

Release files / rust_py_calc_iv-0.1.2.tar.gz

Download URL rust_py_calc_iv-0.1.2.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cd4db96fd2ae71ab1fbdccdb49582ca0872895b3310501caaa0a478f96412bac
BLAKE2b-256 checksum
How to use checksums
ce31d4bf804e47bccc3c131e4cb3229df13c689758e7b7b2b9837916a29f05a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Release files / rust_py_calc_iv-0.1.2-cp311-cp311-win_amd64.whl

Download URL rust_py_calc_iv-0.1.2-cp311-cp311-win_amd64.whl
Size 149.8 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
1274922e804185fd83d7b3b56ad1f0bf0463e80e36cb55a856fd9b189b2679f6
BLAKE2b-256 checksum
How to use checksums
665d593e020c01ab72fd6b22db3f3d3529d21248964ff35b2685ea1c5c03a5bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.13.3

Security for rust-py-calc-iv 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page