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
|
cumulative_pnl = 0
|
||||||
|
|
||||||
for trade in trades:
|
for trade in trades:
|
||||||
if trade['exit_price']:
|
# Skip trades without numeric exit prices
|
||||||
# Convert prices to float if they're strings
|
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'])
|
exit_price = float(trade['exit_price'])
|
||||||
entry_price = float(trade['entry_price'])
|
entry_price = float(trade['entry_price'])
|
||||||
shares = float(trade['shares'])
|
shares = float(trade['shares'])
|
||||||
@ -36,6 +40,9 @@ def plot_trade_history(trades):
|
|||||||
cumulative_pnl += trade_pnl
|
cumulative_pnl += trade_pnl
|
||||||
dates.append(trade['exit_date'])
|
dates.append(trade['exit_date'])
|
||||||
pnl.append(cumulative_pnl)
|
pnl.append(cumulative_pnl)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
# Skip trades where conversion to float fails
|
||||||
|
continue
|
||||||
|
|
||||||
if not dates:
|
if not dates:
|
||||||
return None
|
return None
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user