Skip to main content

Numerically precise Black-Scholes pricing and implied-volatility primitives.

Project description

lets-be-precise

Numerically precise Black-Scholes pricing and implied-volatility primitives.

lbp.bs is a compact compiled kernel whose forward (price) and inverse (implied volatility) paths target the lower edge of double-precision error across the whole (sigma, log(K/F)) plane -- including the deep-OTM and small-t corners where the standard Jaeckel and Cody-erfc paths shed several digits. The wheel also ships lbp.lbr, a thin Cython binding for Peter Jaeckel's "Let's Be Rational" 2013-2023 reference, exposed for honest side-by-side speed and accuracy comparison.

Install

pip install lets-be-precise

Optional extras:

  • lets-be-precise[demo] -- pulls in mpmath so python -m lbp.demos.* comparison modules can run their high-precision truth side.
  • lets-be-precise[dev] -- adds pytest and scipy for the (separately hosted) test suite.

Quick start

import math
import lbp                                # compiled BSM kernel
import lbp.lbr                            # Jaeckel LBR reference (same flags)

sigma, logk = 0.20, 0.15                  # logk = ln(K/F)

C    = lbp.black(sigma, logk)             # call price under our BSM kernel
sig1 = lbp.iv(C, logk)                    # implied vol, lbp's Householder solver

# LBR uses Jaeckel's normalised price b = C / sqrt(F K) and the reflected
# moneyness x = -logk = ln(F/K); see lbp.lbr's docstrings for full detail.
beta = C * math.exp(-logk / 2.0)          # C -> Jaeckel's normalised price
sig2 = lbp.lbr.iv(beta, logk)             # same answer to ~eps

assert abs(sig1 - sig2) < 1e-13

The two implied-vol entry points are deliberately the same shape so the algorithmic differences are timing-clean for benchmarks; see src/lbp/lbr.pyx for the conversion table.

Numerical reliability

The compiled BSM kernel is built on top of mathpf's Mills-ratio primitives, including the cancellation-free symmetric divided difference R_DD(x, dx, +1) = (R(x - dx) - R(x + dx)) / (2 dx). This is the algorithmic counterpart to Jaeckel's two single-purpose expansions inside normalised_black_call_over_vega. They satisfy

b/vega = R(-h-t) - R(-h+t) = 2 t * R_DD(-h, t, +1)

so each Jaeckel expansion matches one R_DD branch. The headline difference:

region what Jaeckel uses R_DD branch accuracy
h < -10, h+t < -9.79 (deep OTM) 17th-order asymptotic series in q CF asymp ladder (n=2/4/6/8) or Taylor both ~eps; AEXP a touch cleaner at the Taylor corner
-10 <= h <= 0, t < 0.21 (small t) 12th-order Taylor in t 5-term Taylor seeded by R'''(x) mathpf wins by up to ~7 bits near h = -10

The small-t gap comes from Jaeckel's coefficient a := 1 + h * Y(h) (with Y(h) := Phi(h)/phi(h)), which suffers cancellation because Y(h) -> -1/h as h -> -infinity. At h = -10, |a| ~ 1/h^2 ~ 0.01 -- two decimal digits are killed before the series even runs. mathpf's R_DD Taylor branch is seeded from R'''(x) and descends to R'(x) via the cancellation-free (r_d3 + 1) / (x^2 + 3) relation, so the offending coefficient never appears.

Worst single cell, inside Jaeckel's actual STEXP dispatch region:

(h, t) = (-9.4, 0.17)            mpmath truth (80 dps)  =  3.72524275689953624e-03
LBR small_t_expansion_of_normalised_black_call_over_vega = 3.72524275689937664e-03
mathpf 2 t * R_DD(-h, t, +1)                             = 3.72524275689953624e-03

LBR    relerr : 4.28e-14   (~192 eps, ~7 bits lost)
mathpf relerr : 0          (bit-exact)

Reproduce on your machine:

pip install lets-be-precise[demo]
python -m lbp.demos.lbr_vs_mathpf

The demo prints both the AEXP-in-gate and STEXP-in-gate tables and explains the dispatch geometry. lbp.lbr also exposes Jaeckel's two file-scope expansions directly as lbp.lbr.aexp_over_vega(h, t) and lbp.lbr.stexp_over_vega(h, t) so users can probe further cells of their own choosing.

License

Proprietary -- see LICENSE. The package is distributed as binary wheels only via PyPI; the underlying Cython / C++ source is not included in the wheel.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

lets_be_precise-0.1.2-cp313-cp313-win_amd64.whl (68.5 kB view details)

Uploaded CPython 3.13Windows x86-64

lets_be_precise-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (392.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

lets_be_precise-0.1.2-cp313-cp313-macosx_11_0_arm64.whl (76.5 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

lets_be_precise-0.1.2-cp312-cp312-win_amd64.whl (68.5 kB view details)

Uploaded CPython 3.12Windows x86-64

lets_be_precise-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (388.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

lets_be_precise-0.1.2-cp312-cp312-macosx_11_0_arm64.whl (76.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

lets_be_precise-0.1.2-cp311-cp311-win_amd64.whl (67.4 kB view details)

Uploaded CPython 3.11Windows x86-64

lets_be_precise-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (373.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

lets_be_precise-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (76.3 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lets_be_precise-0.1.2-cp310-cp310-win_amd64.whl (67.2 kB view details)

Uploaded CPython 3.10Windows x86-64

lets_be_precise-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (359.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

lets_be_precise-0.1.2-cp310-cp310-macosx_11_0_arm64.whl (76.4 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file lets_be_precise-0.1.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2f555df09a754ecdc4e0f2b7f5f870eff877b1ecb2b1357ea038109878b52dae
MD5 a180d28c739c6c22eda514dbdcce0387
BLAKE2b-256 f9952c0e2d68e864143e206ade2c1541f1c788b74f8d7ce6674e29fd3aab6b90

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.2-cp313-cp313-win_amd64.whl:

Publisher: build_wheels.yml on quants-net/lets-be-precise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lets_be_precise-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c0e3ffa8321087453f2a48590a43baee2b51ab2f7948c941edeeceecabbe0c19
MD5 2d1b506ccdb3e29515cdda485a605eaf
BLAKE2b-256 3975267ba33e5ac31e38be8971bff7695eb240d0b351b9d3ac9194872b9d0977

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.2-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on quants-net/lets-be-precise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lets_be_precise-0.1.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3e55621df355b3cd0aab813f8b91f7dc9bcb99f25eed09907a687dbdabc98d2a
MD5 a2e3ad9fdc9859de2dc1ced153f3c950
BLAKE2b-256 56b20eaaa6d829ab907d4482691e3750490d84781e674fd9a0cd7d3d4df204d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on quants-net/lets-be-precise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lets_be_precise-0.1.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0a63aeccfbf62aea851aa3c27a8f937ad5a60ed2128b7883691c356a8fe7faca
MD5 83ca3c57ecef2681ae5e6a0d6948db71
BLAKE2b-256 a2aa14e3e0c025c556e6f82596be9c20ff559f159b73e4759d761de5dc8ec127

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.2-cp312-cp312-win_amd64.whl:

Publisher: build_wheels.yml on quants-net/lets-be-precise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lets_be_precise-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e0e891a60c8fc23aa898b952a7cab4d831b46c93ced453d187012e818c42f216
MD5 2d076e40db1149e5503f5b034a03a147
BLAKE2b-256 ab12ba49721f7249b8b688a4d90b7e4b68782a5918aeb0aee2508fa5479c8baf

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on quants-net/lets-be-precise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lets_be_precise-0.1.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 48a79e3f7649c2efa99b56cb7d220d29f592a75f085a781e49cd4c0ce7fcf383
MD5 3eab7369d3b53192513af4a365c13612
BLAKE2b-256 3968511e50c7bad9815402e354f952cc9d88ef5a035fae50cc32a929188fea9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on quants-net/lets-be-precise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lets_be_precise-0.1.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fe85e96d5617d1ec296724eb169e263cec61fdf6db40727f0ebe9ecf03f95634
MD5 010e3d123b91f4c6776559f817e20fed
BLAKE2b-256 c782c141d2b9043b5267ea0da32453c5e14e10077d24ddc06d0ae29680d98272

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.2-cp311-cp311-win_amd64.whl:

Publisher: build_wheels.yml on quants-net/lets-be-precise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lets_be_precise-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 47abc0e79be14716a1af8c026fcc3e1ede02b2975da3931505433e9e72313524
MD5 5fffe8c76076ac255371eb404b4a8e64
BLAKE2b-256 c2c84888dcccbcdc0d509597a715d9a43ede79625afcf67550edb6fbb2ba8d95

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.2-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on quants-net/lets-be-precise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lets_be_precise-0.1.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9cd7d0789d1ede6768f79e88bf70b125109d467ac24e0884b00433d13e955d3b
MD5 0ba1b5bc0d72dfe2be0b7899d80fb6da
BLAKE2b-256 1922217803058b06b3ebb2d32eed80f8fbf7018c0eebd40fa119ff2473bc725a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on quants-net/lets-be-precise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lets_be_precise-0.1.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 590e82911209bb28ef54d9356ff69666b3d3f6dab00c4b50ca51c34fa51f0ad3
MD5 89503ad479c7524496c8c1134bfe15db
BLAKE2b-256 888eea9325bde4e7d18e43042ea0a139871ef3100ef99d2342804f25f0e02558

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.2-cp310-cp310-win_amd64.whl:

Publisher: build_wheels.yml on quants-net/lets-be-precise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lets_be_precise-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9881046202e5c49565cf486597488b2b6df6b570e0f47b44ad09a64abefaabac
MD5 2013fdd52665b08e17535a5f378264b4
BLAKE2b-256 5374a8c5fa8ab68890883877bf3d8636b119bba3b4b3d15c7b3a63e4baf7def6

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.2-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build_wheels.yml on quants-net/lets-be-precise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lets_be_precise-0.1.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 243bd914638e6c01edfa1fe000e114bb21993a123445350a0c62227189cdfbea
MD5 9992382fdb3fb291ac81df74633a47b4
BLAKE2b-256 471505179512183e88c6cadf9817995b0bd4cf3f3fd438152884722a4beb07ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.2-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: build_wheels.yml on quants-net/lets-be-precise

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page