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
|
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 trading.position_calculator import PositionCalculator
|
||||||
from utils.data_utils import get_current_prices
|
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
|
cash_balance = portfolio_data['cash_balance'] if portfolio_data else 0
|
||||||
|
|
||||||
# Calculate total portfolio value including open positions
|
# Calculate total portfolio value including open positions
|
||||||
open_positions = get_open_trades_summary()
|
open_trades = get_open_trades()
|
||||||
total_position_value = 0
|
total_position_value = 0
|
||||||
|
|
||||||
if open_positions:
|
if open_trades:
|
||||||
# Get current prices for all open positions
|
# 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)
|
current_prices = get_current_prices(tickers)
|
||||||
|
|
||||||
# Calculate total value of open positions
|
# Calculate total value of open positions
|
||||||
for position in open_positions:
|
position_values = {}
|
||||||
ticker = position['ticker']
|
for trade in open_trades:
|
||||||
|
ticker = trade['ticker']
|
||||||
current_price = current_prices.get(ticker, 0)
|
current_price = current_prices.get(ticker, 0)
|
||||||
shares = position['total_shares']
|
shares = trade['shares']
|
||||||
total_position_value += current_price * 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
|
total_portfolio_value = cash_balance + total_position_value
|
||||||
|
|
||||||
# Display portfolio information
|
# Display portfolio information
|
||||||
col1, col2 = st.columns(2)
|
col1, col2, col3 = st.columns(3)
|
||||||
with col1:
|
with col1:
|
||||||
st.info(f"Available Cash: ${cash_balance:,.2f}")
|
st.info(f"Available Cash: ${cash_balance:,.2f}")
|
||||||
with col2:
|
with col2:
|
||||||
|
st.info(f"Positions Value: ${total_position_value:,.2f}")
|
||||||
|
with col3:
|
||||||
st.info(f"Total Portfolio Value: ${total_portfolio_value:,.2f}")
|
st.info(f"Total Portfolio Value: ${total_portfolio_value:,.2f}")
|
||||||
|
|
||||||
col1, col2 = st.columns(2)
|
col1, col2 = st.columns(2)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user