vollib / py_vollib

MIT License
308 stars 68 forks source link

ModuleNotFoundError: No module named '_testcapi' #27

Open posidonius opened 8 months ago

posidonius commented 8 months ago

from py_vollib.black_scholes_merton import black_scholes_merton

raises

ModuleNotFoundError: No module named '_testcapi'

Python 3.11.7 py-vollib 1.0.1

Issue mentioned elsewhere: https://github.com/vollib/py_vollib/issues/11 https://github.com/vollib/py_vollib/issues/20

Is this issue still a known problem with the pip package?

alexandercommon commented 6 months ago

What finally worked for me, as of April 2024, was to install both py_vollib AND py_lets_be_rational from github rather than PyPI.

When they said it was fixed in Github in issue 11, I'm pretty sure they meant it was fixed in py_lets_be_rational. Even if you install py_vollib from github, pip will still grab py_lets_be_rational from PyPI, so you have to install that from Github first.

pip install git+https://github.com/vollib/py_lets_be_rational.git pip install git+https://github.com/vollib/py_vollib.git

>>> from py_vollib.black import black
>>> flag = 'c'  # 'c' for call, 'p' for put
>>> S = 95  # price of the underlying
>>> K = 100  # strike
>>> t = .2  # annualized time to expiration
>>> r = .2  # interest-free rate
>>> sigma = .2  # implied volatility
>>> black(flag, S, K, t, r, sigma)
1.4739294832475103