fix: Handle non-numeric exit prices in trade history plotting

This commit is contained in:
Bobby (aider) 2025-02-13 08:42:08 -08:00
parent 0b07861265
commit fb27bf3003

View File

@ -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