fix: Handle non-numeric exit prices in trade history plotting
This commit is contained in:
parent
0b07861265
commit
fb27bf3003
@ -26,8 +26,12 @@ def plot_trade_history(trades):
|
||||
cumulative_pnl = 0
|
||||
|
||||
for trade in trades:
|
||||
if trade['exit_price']:
|
||||
# Convert prices to float if they're strings
|
||||
# Skip trades without numeric exit prices
|
||||
if not trade['exit_price'] or not isinstance(trade['exit_price'], (int, float)):
|
||||
continue
|
||||
|
||||
try:
|
||||
# Convert prices to float if they're strings and are numeric
|
||||
exit_price = float(trade['exit_price'])
|
||||
entry_price = float(trade['entry_price'])
|
||||
shares = float(trade['shares'])
|
||||
@ -36,6 +40,9 @@ def plot_trade_history(trades):
|
||||
cumulative_pnl += trade_pnl
|
||||
dates.append(trade['exit_date'])
|
||||
pnl.append(cumulative_pnl)
|
||||
except (ValueError, TypeError):
|
||||
# Skip trades where conversion to float fails
|
||||
continue
|
||||
|
||||
if not dates:
|
||||
return None
|
||||
|
||||
Loading…
Reference in New Issue
Block a user