【问题标题】:Handle specific exception from python package处理来自 python 包的特定异常
【发布时间】:2018-09-13 08:20:20
【问题描述】:

我想以特定方式处理来自 py_vollib/py_lets_be_rational 的以下异常。

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

我做错了什么?任何帮助将不胜感激。

【问题讨论】:

    标签: python exception exception-handling python-3.7


    【解决方案1】:

    the implementation,你漏掉了句尾的句号:

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

    我没有看到此检查的重点,因为这将始终是创建异常时使用的消息。

    【讨论】:

    • 抱歉,我发现了这一点,并认为我实际上并没有发送问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-09
    • 2011-09-01
    • 2012-09-20
    • 1970-01-01
    • 2016-12-04
    • 1970-01-01
    相关资源
    最近更新 更多