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.lbp 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)
mlogk = -logk                             # lbp's k_or_mlogk on the mlogk branch
                                          # (matches LBR's x = ln(F/K))

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

# LBR uses Jaeckel's normalised price b = C / sqrt(F K) and takes the
# reflected moneyness x = ln(F/K) directly (same numeric value as mlogk).
beta = C * math.exp(-logk / 2.0)          # C -> Jaeckel's normalised price
sig2 = lbp.lbr.iv(beta, mlogk)            # 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.4-cp313-cp313-win_amd64.whl (69.5 kB view details)

Uploaded CPython 3.13Windows x86-64

lets_be_precise-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (391.9 kB view details)

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

lets_be_precise-0.1.4-cp313-cp313-macosx_11_0_arm64.whl (77.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

lets_be_precise-0.1.4-cp312-cp312-win_amd64.whl (69.5 kB view details)

Uploaded CPython 3.12Windows x86-64

lets_be_precise-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (388.9 kB view details)

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

lets_be_precise-0.1.4-cp312-cp312-macosx_11_0_arm64.whl (77.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

lets_be_precise-0.1.4-cp311-cp311-win_amd64.whl (68.4 kB view details)

Uploaded CPython 3.11Windows x86-64

lets_be_precise-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (373.0 kB view details)

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

lets_be_precise-0.1.4-cp311-cp311-macosx_11_0_arm64.whl (77.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lets_be_precise-0.1.4-cp310-cp310-win_amd64.whl (68.2 kB view details)

Uploaded CPython 3.10Windows x86-64

lets_be_precise-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (359.7 kB view details)

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

lets_be_precise-0.1.4-cp310-cp310-macosx_11_0_arm64.whl (77.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 916f441b9db9d087ec9cfe09bd6ecd1a5c288ee2be70ef4a66279c192c0d6904
MD5 5b6832402ee5c1b9e20344b136bf3f4c
BLAKE2b-256 3c85e5d7a6f9a6fcc857a2ea0b7c85e71d0ef0556983b3bffa4fed4e35095d14

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.4-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.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dcd2194d08fb22e105d5190f82f5fb8f4e9e590df8091e20c384cd61d1175b2a
MD5 76546e14ff22c55ae01a8bb08a9cd3d9
BLAKE2b-256 a43f6da0238b22d70055740788e6a98c7f6e0d503cb2bd570cbfa62f5d1f356f

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.4-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.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b042998705e3efa2ee74c45e323286b3cd70e669f8fad5d6d2732d4681dad22e
MD5 16e5b5c90688fb119cc276f3dd09020a
BLAKE2b-256 f7b76f14204fd20540547fb76ae1119c38340b4bfb9a7f3065fda414f08e8ad9

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.4-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.4-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 46066f997c21cbf7d8cca4efaafea9f50f7707a280172a3d40eb8d128231d99c
MD5 adc5dd5f82357c1541014043765e3e9e
BLAKE2b-256 88a5e72662f780d6abf998b8ec526b40ced47cf0c6e7d8f0c17cb2d8774112c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.4-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.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a38d2e3df27e3e5a0fe1764551e13a2e7ecbc5f348145ccb69e83ca68638bc61
MD5 fdd28d14cee5bb107726efa477b9ea1b
BLAKE2b-256 1773726b0e845ed6d8fb4fae90650d924089e07e584ddf59dee53a9f1ce85b17

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.4-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.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d6b5e58fc7a517d586cbab24eb70d590ce39c8cb5b7c6ddd664b9ba3534f7732
MD5 0c560107b5be2850c99bcd199a355b57
BLAKE2b-256 8a49781cf023a8986926edacdc814b0d98d1e7ec3fb7c9aa81233943e7f45c15

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.4-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.4-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 fb8b1f04d7c74bdb58ca790da9e912d34e83511fe8a0b431c7817e3f01216be4
MD5 711fe07b6f94de0712c99a7ac69dcb14
BLAKE2b-256 e35a1806cd8d3f728d4a647380e4492a6837a8a65d5fbea8403414a397a1a124

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.4-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.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2d476ff7e63e148a44a6f8fc7ebccfcf22a271a2f3704ea0b66bfbba1e74d51e
MD5 ec69c8ba6ba502abdfffd17c3d30bc6a
BLAKE2b-256 b3e8bbc926729ed3986c1d3dab6fdb98dc94fd27da72e999bab458d9e438de1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.4-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.4-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a8716cd756eda43e4a9715697bf7651500016655bfb9c811a755dadc935e426
MD5 d7a97e5b9dd03518174fa9677c1c1639
BLAKE2b-256 97401015652f59c582e05865ba4b990356e6bec0289223f1117d91db8916eaaa

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.4-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.4-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 567b06e8635e50bed0831db2555648ac98cbc4ff7e068d702595b9531856d6e1
MD5 337e0ea30da548f2a204606d57e95501
BLAKE2b-256 ca9658556e41c9b94c29ac21bda0a918c3adc20faeed2169b691e231b20061e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.4-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.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.4-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e549b34b027e40a9d72b729160289c5e0f6327a86f5c7f977217027b4c695654
MD5 66ed6073f0b92c76234fdec6795b17fb
BLAKE2b-256 839958310ff83d2b3ab38e052723514a3361bcf062e7a328beb674e6be399cb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.4-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.4-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lets_be_precise-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 897d59390d935b1a8d35ddfc63bf2519c91ea4fa6c9fb752e0a6e6d6f7690480
MD5 b1067313c67b334ff284fd2b898011b9
BLAKE2b-256 069d24da536394b9c2c64342963f58bc6fc7be5779d2f26e0019453802ce392f

See more details on using hashes here.

Provenance

The following attestation bundles were made for lets_be_precise-0.1.4-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