Skip to content

Commit

Permalink
Return 0.0 if market price is NaN.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brndnmtthws committed Feb 15, 2024
1 parent 42af123 commit 78867fc
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion thetagang/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 78867fc

Please sign in to comment.