From 6097ce63674b46ab7a1c70eef9cd180ec57acfd1 Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Thu, 13 Feb 2025 12:55:44 -0800 Subject: [PATCH] feat: Improve portfolio value calculation with detailed open trades tracking --- src/pages/trading/trading_system_page.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/pages/trading/trading_system_page.py b/src/pages/trading/trading_system_page.py index 50f1732..3f51533 100644 --- a/src/pages/trading/trading_system_page.py +++ b/src/pages/trading/trading_system_page.py @@ -1,5 +1,5 @@ import streamlit as st -from trading.journal import get_latest_portfolio_value, get_open_trades_summary +from trading.journal import get_latest_portfolio_value, get_open_trades_summary, get_open_trades from trading.position_calculator import PositionCalculator from utils.data_utils import get_current_prices @@ -12,28 +12,33 @@ def trading_system_page(): cash_balance = portfolio_data['cash_balance'] if portfolio_data else 0 # Calculate total portfolio value including open positions - open_positions = get_open_trades_summary() + open_trades = get_open_trades() total_position_value = 0 - if open_positions: + if open_trades: # Get current prices for all open positions - tickers = [pos['ticker'] for pos in open_positions] + tickers = list(set(trade['ticker'] for trade in open_trades)) current_prices = get_current_prices(tickers) # Calculate total value of open positions - for position in open_positions: - ticker = position['ticker'] + position_values = {} + for trade in open_trades: + ticker = trade['ticker'] current_price = current_prices.get(ticker, 0) - shares = position['total_shares'] - total_position_value += current_price * shares + shares = trade['shares'] + position_value = current_price * shares + position_values[ticker] = position_values.get(ticker, 0) + position_value + total_position_value += position_value total_portfolio_value = cash_balance + total_position_value # Display portfolio information - col1, col2 = st.columns(2) + col1, col2, col3 = st.columns(3) with col1: st.info(f"Available Cash: ${cash_balance:,.2f}") with col2: + st.info(f"Positions Value: ${total_position_value:,.2f}") + with col3: st.info(f"Total Portfolio Value: ${total_portfolio_value:,.2f}") col1, col2 = st.columns(2)