From ca24ac9f91fb7ba713ce8f6e571b76009f5a1510 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Thu, 15 Feb 2024 16:45:30 -0500 Subject: [PATCH] Return 0.0 if market price is NaN. On the odd chance `ticker.marketPrice()` returns NaN, return 0.0 instead. This is very rare, and shouldn't happen, but it might when you have contracts that are way OTM and near expiration. This may hopefully address #368. --- thetagang/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thetagang/util.py b/thetagang/util.py index c070a7509..8f386c438 100644 --- a/thetagang/util.py +++ b/thetagang/util.py @@ -217,7 +217,7 @@ def midpoint_or_market_price(ticker: Ticker) -> float: # Fallback to the model price if the greeks are available return ticker.modelGreeks.optPrice else: - return ticker.marketPrice() + return ticker.marketPrice() if not util.isNan(ticker.marketPrice()) else 0.0 return ticker.midpoint()