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

Uploaded CPython 3.13Windows x86-64

lets_be_precise-0.1.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (390.7 kB view details)

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

lets_be_precise-0.1.3-cp313-cp313-macosx_11_0_arm64.whl (77.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

lets_be_precise-0.1.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (387.3 kB view details)

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

lets_be_precise-0.1.3-cp312-cp312-macosx_11_0_arm64.whl (77.2 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

lets_be_precise-0.1.3-cp311-cp311-win_amd64.whl (68.5 kB view details)

Uploaded CPython 3.11Windows x86-64

lets_be_precise-0.1.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (371.7 kB view details)

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

lets_be_precise-0.1.3-cp311-cp311-macosx_11_0_arm64.whl (77.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

lets_be_precise-0.1.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (358.5 kB view details)

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

lets_be_precise-0.1.3-cp310-cp310-macosx_11_0_arm64.whl (77.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 831890752e952054a6eaa26a557f11b9b79500a2b474de537db285d6e574a495
MD5 4625f5306d4c0796e849a760d804e981
BLAKE2b-256 1cdb5f9209ee5b18a05ed3460d8319e6cbdcf636b362cf765291109a1bfeb1b3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 262c9d88af0cd0b7b44cc051458be44714fd30a3afb58a9f68d8fe9f613136ea
MD5 4a7c6c7367d5b3c3b27cf8ef64feaef1
BLAKE2b-256 80e555601dc66d57c0225be17694fe5bcad182bdf148fded416c6796bce89b6d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 04ed3d2c576a934fcca474e37ef80dd33acdefb2f118f4b3d2ea4a694f5a7505
MD5 c7cf64176e2b8b4895995f60fe719269
BLAKE2b-256 3888bf219e153c3f0e47955efee0decf3fcd74c6f3ad6ba4303321eca3d68978

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 22791ca00e5f0a4d1aa7a7f59774932ef1661973d6b63bc6554638867291edcb
MD5 1436341ee005b40e46f765875d85048a
BLAKE2b-256 64dc9eae2224622f0978a59ae427655d94b9d70058eaaeb0ff80237513d2021f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 de7e7420cac87de486228ca52c00d7077a6e035ef699ac71301e4955abef09bb
MD5 20d8b58d831bd8bf74a08f6bd73a99ef
BLAKE2b-256 5d1b38816103dad7e90ec01e1b5564f79c6c1e72dece8bfef7eff11a2aa8b51c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 84bdce8ef8f9de8e5af999f09a7407c7be252bc14fd19ad6ea099957bffcb3c3
MD5 04fc9ec84bf2ccfd245afd10b3993930
BLAKE2b-256 c5df80d9ae7fb6ea03b818e23f2b5f42d3f64eeb46eb96e2363d2aa7efd876a6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e43ee6bd84a6b02cde6001e2115e144b682b403281e88288e9aa744e94296879
MD5 051ef59c9132a75ff47643333ad441ba
BLAKE2b-256 022dd33fa51649fb5a64fb6c5063ffd1995f19dcd0a9d7838d3d8a84f917ec88

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f8c3d6a3aa54a35c7fb8a709230df7428e3df44af72aef4b00bb5a316b28fecd
MD5 30c28efdebd8a402027133d74f38f9d7
BLAKE2b-256 6fd33839693dc87e3a0223ee92ac755e207c99198e4c5b30c906ecd1bb9f411a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 806992ac09afbae41d05d2199da742c4fe0d62bb57f98cafe58749d0f44486e9
MD5 6a877c895ee48d07570c16e00e4176a7
BLAKE2b-256 9a5e1c07126f6913a6a997b9601c8011d2850f4e002ae7ad2b87898d4d01c941

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b8e027790b2925d53e0e39c301844ab02cd35d4e35161f2e1e41f05bce7bc287
MD5 2ec7bf1dc61fcca4f22b701b7bd8449b
BLAKE2b-256 4e9783aab263078adee10ba751b5e708ed0de4338d1ff4dea95eb9e80899ff55

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f8da6441af71a03ad7a29712e2806e1f15cac35a7c4cc72af9b66e7b8f5bf324
MD5 462b9367dcfd54b00e412428917737e4
BLAKE2b-256 44f49f6d31f3cd0ad80d7fa9343f59f73e483e4f8dd82485effa9b292310d8ff

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for lets_be_precise-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0e30cfe750ace2457a05f82d580722a2defec685944542e7895bd4b1bcdca0d9
MD5 7283f61bb36dd50af20ad948aaf3dbc7
BLAKE2b-256 9ff4759da24d2ebe0287bab8ab841d9f27056a14ba1fb893ed55ecd09ee1ab1a

See more details on using hashes here.

Provenance

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