py-lets-be-rational
raw JSON → 1.0.1 verified Fri May 01 auth: no python
Pure Python implementation of Peter Jaeckel's LetsBeRational, providing high-precision computation of implied volatility and option pricing using rational approximations. Current version 1.0.1, released on PyPI with no updates since 2018. Low maintenance but stable.
pip install py-lets-be-rational Common errors
error ModuleNotFoundError: No module named 'lets_be_rational' ↓
cause Package installed but import name is not obvious.
fix
Use
import lets_be_rational or from lets_be_rational import ImpliedVolatility. The package name and module name differ. error AttributeError: module 'lets_be_rational' has no attribute 'ImpliedVolatility' ↓
cause Outdated version or typo in class name.
fix
Run
pip install --upgrade py-lets-be-rational and check spelling: class is ImpliedVolatility (capital I, V). Warnings
gotcha Import from `lets_be_rational` not `py_lets_be_rational` or `letsberational`. The package is installed as `py-lets-be-rational` but the module is named `lets_be_rational`. ↓
fix Use `from lets_be_rational import ImpliedVolatility`.
gotcha The library expects forward price, not spot price. If you pass spot, results will be wrong for nonzero interest/dividends. ↓
fix Compute forward = spot * exp((r - q) * T) before calling.
gotcha Option price must be a positive float. Passing zero or negative price may cause silent errors or zero division. ↓
fix Ensure option price > 0.
Imports
- ImpliedVolatility wrong
from py_lets_be_rational import ImpliedVolatilitycorrectfrom lets_be_rational import ImpliedVolatility - Black wrong
from py_lets_be_rational import Blackcorrectfrom lets_be_rational import Black
Quickstart
from lets_be_rational import ImpliedVolatility
import math
iv = ImpliedVolatility()
# Example: forward=1.2, strike=1.0, time to expiry=0.5, option price=0.2, call=True
sigma = iv.implied_volatility(1.2, 1.0, 0.5, 0.2, True)
print(f"Implied Volatility: {sigma:.6f}")