feat: Improve portfolio value calculation with detailed open trades tracking
This commit is contained in:
parent
3e1775534c
commit
6097ce6367
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user