Skip to content

Commit

Permalink
Better handling of NaN closing prices
Browse files Browse the repository at this point in the history
  • Loading branch information
brndnmtthws committed Jul 24, 2024
1 parent 9e41176 commit 6c4386a
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions thetagang/portfolio_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,15 +1370,12 @@ def close_positions(self, positions: List[Any]) -> None:
if is_short
else round(get_higher_price(ticker), 2)
)
if util.isNan(price):
if util.isNan(price) or math.isnan(price) or not price:
# if the price is near zero or NaN, use the minimum price
console.print(
f"[yellow]Unable to close {position.contract.localSymbol} "
"because market price data unavailable, skipping[/yellow]",
f"[yellow]Market price data unavailable for {position.contract.localSymbol}, "
"using ticker.minTick={ticker.minTick}[/yellow]",
)
continue

if not price:
# if the price is near zero, use the minimum price
price = ticker.minTick

qty = abs(position.position)
Expand Down

0 comments on commit 6c4386a

Please sign in to comment.