处理来自python包的特定异常

2024-06-16 13:22:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我想以特定的方式处理py\u vollib/py\u lets\u的以下异常。你知道吗

py_lets_be_rational.exceptions.BelowIntrinsicException: The volatility is below the intrinsic value.

尝试此操作但未成功:

from py_vollib.black.implied_volatility import implied_volatility as impl_vol_b
from py_lets_be_rational.exceptions import BelowIntrinsicException

try:
    call_vol = impl_vol_b(discounted_option_price, F, K, r, t, type)
except BelowIntrinsicException as e:
    if str(e) != 'The volatility is below the intrinsic value':
        raise
    else:
        call_vol = 0

我做错什么了?任何帮助都将不胜感激。你知道吗


Tags: thepyisvaluebeexceptionsbelowrational
1条回答
网友
1楼 · 发布于 2024-06-16 13:22:44

the implementation,你错过了句子末尾的句点:

if str(e) != 'The volatility is below the intrinsic value.':

我看不出这个检查有什么意义,因为创建异常时总是使用这个消息。你知道吗

相关问题 更多 >