在base.py里
def calculate_option_impv(self) -> None:
""""""
if not self.tick or not self.underlying:
return
underlying_price = self.underlying.mid_price
if not underlying_price:
return
underlying_price += self.underlying_adjustment
# Adjustment for crypto inverse option contract
if self.inverse:
ask_price = self.tick.ask_price_1 * underlying_price
bid_price = self.tick.bid_price_1 * underlying_price
else:
ask_price = self.tick.ask_price_1
bid_price = self.tick.bid_price_1
self.ask_impv = self.calculate_impv(
ask_price,
underlying_price,
self.strike_price,
self.interest_rate,
self.time_to_expiry,
self.option_type
)
self.bid_impv = self.calculate_impv(
bid_price,
underlying_price,
self.strike_price,
self.interest_rate,
self.time_to_expiry,
self.option_type
)
self.mid_impv = (self.ask_impv + self.bid_impv) / 2
因为self.calculate_impv返回值有可能为0,那么这个地方需不需要判断返回值为0的情况,如果最终self.mid_impv等于0,那么在计算greeks的时候就会出现除数为0的错误