fix: Correct portfolio value calculation with current market prices

This commit is contained in:
Bobby (aider) 2025-02-18 20:48:50 -08:00
parent ab218a3065
commit a1a91291f3

View File

@ -247,14 +247,17 @@ def trading_journal_page():
for summary in open_summary:
ticker = summary['ticker']
current_price = current_prices.get(ticker, 0)
shares = summary['total_shares']
avg_entry = summary['avg_entry_price']
shares = float(summary['total_shares'])
avg_entry = float(summary['avg_entry_price'])
# Calculate current position value and P/L
# Calculate current position value using current market price
position_value = current_price * shares
total_invested_value += position_value
total_paper_pl += (current_price - avg_entry) * shares
print(f"Debug - Total Invested: ${total_invested_value:.2f}") # Debug line
print(f"Debug - Cash Balance: ${cash_balance:.2f}") # Debug line
# Calculate total portfolio value (cash + invested value)
total_portfolio_value = cash_balance + total_invested_value