fix: Convert trade prices and shares to float to prevent type errors

This commit is contained in:
Bobby (aider) 2025-02-13 08:40:44 -08:00
parent 8d76d820fe
commit 0b07861265

View File

@ -27,7 +27,12 @@ def plot_trade_history(trades):
for trade in trades: for trade in trades:
if trade['exit_price']: if trade['exit_price']:
trade_pnl = (trade['exit_price'] - trade['entry_price']) * trade['shares'] # Convert prices to float if they're strings
exit_price = float(trade['exit_price'])
entry_price = float(trade['entry_price'])
shares = float(trade['shares'])
trade_pnl = (exit_price - entry_price) * shares
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)