I would like to handle the following Exception from py_vollib/py_lets_be_rational in specific way.
JavaScript
x
2
1
py_lets_be_rational.exceptions.BelowIntrinsicException: The volatility is below the intrinsic value.
2
Tried this without success:
JavaScript
1
11
11
1
from py_vollib.black.implied_volatility import implied_volatility as impl_vol_b
2
from py_lets_be_rational.exceptions import BelowIntrinsicException
3
4
try:
5
call_vol = impl_vol_b(discounted_option_price, F, K, r, t, type)
6
except BelowIntrinsicException as e:
7
if str(e) != 'The volatility is below the intrinsic value':
8
raise
9
else:
10
call_vol = 0
11
what am I doing wrong? any help would be appreciated.
Advertisement
Answer
Looking at the implementation, you’re missing the period at the end of the sentence:
JavaScript
1
2
1
if str(e) != 'The volatility is below the intrinsic value.':
2
I don’t see the point in this check because that will always be the message the exception is created with.