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.5-cp313-cp313-win_amd64.whl (71.6 kB view details)

Uploaded CPython 3.13Windows x86-64

lets_be_precise-0.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (409.8 kB view details)

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

lets_be_precise-0.1.5-cp313-cp313-macosx_11_0_arm64.whl (79.3 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

lets_be_precise-0.1.5-cp312-cp312-win_amd64.whl (71.6 kB view details)

Uploaded CPython 3.12Windows x86-64

lets_be_precise-0.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (406.8 kB view details)

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

lets_be_precise-0.1.5-cp312-cp312-macosx_11_0_arm64.whl (79.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

lets_be_precise-0.1.5-cp311-cp311-win_amd64.whl (70.4 kB view details)

Uploaded CPython 3.11Windows x86-64

lets_be_precise-0.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (390.8 kB view details)

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

lets_be_precise-0.1.5-cp311-cp311-macosx_11_0_arm64.whl (79.1 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

lets_be_precise-0.1.5-cp310-cp310-win_amd64.whl (70.1 kB view details)

Uploaded CPython 3.10Windows x86-64

lets_be_precise-0.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (377.3 kB view details)

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

lets_be_precise-0.1.5-cp310-cp310-macosx_11_0_arm64.whl (79.2 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f42e1f8943cd1d6d882527a65bbd9bfb48900981fa8dda7f131d31ae2a3a69f1
MD5 1e109247480ddb5867ac8d3d5df3e533
BLAKE2b-256 62e1fcb04c134040808ce4f7b6209e1c74058d5d550fff5a906290d473af7d46

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b17458fdf6216d88c896e4da9d23666dffac3b702dc8cec7e6466c49c1890994
MD5 c71cb79dfc76ea3cdc9f3d3106d0d873
BLAKE2b-256 3bf8654e1bf87a95a1a9be54bc26f5651b5c833c960dae411e7563916a59174b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e94eba8b547ddeeb7e0faacb973775f431de578a51ff80cfb5f63ae7ceb6c47f
MD5 465e8a0cfd34f7a7f0611c7c251ac793
BLAKE2b-256 6d255b2e12da7726b027d7025cfe6a54b56f483cafe72259eb1c5c66e87bfc97

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0f192453793065fc568f612b05ae61d37949cd9a86954f5c6e46681d832ecf46
MD5 c0c617e2074f651084ab5f683b8fee8a
BLAKE2b-256 1112d0658b803a2a28a29276d9881f716753231ce10720f978f1c3c98d574ca1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f9209ad6c459f4a814ff8bc575efeb775b556446842694b0c468100dd37ee673
MD5 6b72c3a4792d155bc09f0522bea0e2be
BLAKE2b-256 5cd71cdabb97eef133cd3de13046d73f4dec56677de8b41fd2a1c38134b0272c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1c79b96cc7c3a06739e1f427e458c8a0b1792471537d764cea42dbb8f817b2a6
MD5 d1d3ce02f100707f2f1d03ee99196efe
BLAKE2b-256 968a21232007e56a0161e9640ef4bc7d3509f69b192b5e5ed19055db536cff7d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 25f689693d37591add2f0344e0ebf70f93eb9710f48527ebc3bcd8a681f0f446
MD5 508aba62c5297d601db6da38434b8db6
BLAKE2b-256 67d4357a8027eba1a6750842cf50fb723ee710ceab9705445c3fc23c3f3bf8d5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2cde6f574c1c734af51509626103cad768c638222098c7674b2503579e380ac6
MD5 8cb80d1b4b86529b440b4c530129eb99
BLAKE2b-256 b1ccc4901dcfb29daad72d4d7a693e5bbeeb6598f732360b1cf0d1001ba5ed35

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.5-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9ff2f4b489f85f9d2225c1140bec29d3a235c4dbe617271d4c439161934e9eff
MD5 0e15385e20dbfe591b618a17e3b00ee8
BLAKE2b-256 78f27b3a71dca0ac00a3cfa6b4ca17d2ba3b5e4618e4e5131252a1dd3e1e6631

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 26a53c25f841b7630f94a76164ede5e2867da1746a41a50407f4096b216a4fbc
MD5 936a313e67c002312ea4c5f514d9a41c
BLAKE2b-256 2217039edc6f00edc13edea8e9c67ccf51829848ae0fdf5146a76609505e25bc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 96bf9f1344030a6c5fd96008c6746ba584a10124c448a8452e652e5e88865785
MD5 a1c124c5793602e7ddf713a8aff9b6b6
BLAKE2b-256 bf9828afea5e0a21a52bd64bb73908f131306e038c7e1948c472519db54f2af5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.5-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e33973c9463f1eae0a85aabf76d0e349517452613edfefc15122540ce36c6336
MD5 5ebab765d88bc779af555c039203bd45
BLAKE2b-256 8ee8be078106cd8220bba1ee86b5cb3f3703cb43fa72e0354f8a4e3ea6b84ae7

See more details on using hashes here.

Provenance

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