Skip to content

Commit

Permalink
And special handling to marked down position PnL
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Jan 30, 2025
1 parent 7590208 commit 231b909
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tradeexecutor/state/position.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,10 @@ def get_unrealised_and_realised_profit_percent(
if not valuation_price:
valuation_price = self.last_token_price

assert valuation_price, "Cannot value unrealised PnL without an explicit valuation price for the unsold portion"
# Marked down positions need to have special handling
if not self.is_marked_down():
assert valuation_price, f"Cannot value unrealised PnL without an explicit valuation price for the unsold portion.\n" \
f"Position was: {self}, quantity left: {quantity_left_sell}, valuation price: {valuation_price}"
unrealised_equity = valuation_price * float(quantity_left_sell)

avg_price = self.get_average_price()
Expand Down

0 comments on commit 231b909

Please sign in to comment.