feat: Enhance portfolio overview with dynamic value calculation and cash balance input
This commit is contained in:
parent
bd4dce4f42
commit
4659496889
@ -235,19 +235,53 @@ def trading_journal_page():
|
||||
# Portfolio overview section
|
||||
st.subheader("Portfolio Overview")
|
||||
col1, col2, col3 = st.columns(3)
|
||||
|
||||
|
||||
# Get cash balance
|
||||
latest_portfolio = get_latest_portfolio_value()
|
||||
cash_balance = latest_portfolio['cash_balance'] if latest_portfolio else 0
|
||||
|
||||
# Calculate total invested value and paper P/L
|
||||
total_invested_value = 0
|
||||
total_paper_pl = 0
|
||||
if open_summary:
|
||||
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']
|
||||
|
||||
position_value = current_price * shares
|
||||
total_invested_value += position_value
|
||||
total_paper_pl += (current_price - avg_entry) * shares
|
||||
|
||||
# Calculate total portfolio value
|
||||
total_portfolio_value = cash_balance + total_invested_value
|
||||
|
||||
with col1:
|
||||
st.metric("Total Portfolio Value", f"${total_portfolio_value:,.2f}")
|
||||
st.metric("Cash Balance", f"${cash_balance:,.2f}",
|
||||
f"{(cash_balance/total_portfolio_value)*100:.1f}% of Portfolio" if total_portfolio_value > 0 else "")
|
||||
|
||||
# Add input for cash balance
|
||||
new_cash_balance = st.number_input(
|
||||
"Cash Balance ($)",
|
||||
value=cash_balance,
|
||||
step=100.0,
|
||||
format="%.2f"
|
||||
)
|
||||
|
||||
if new_cash_balance != cash_balance:
|
||||
# Update cash balance if changed
|
||||
update_portfolio_value(total_portfolio_value, new_cash_balance)
|
||||
st.rerun()
|
||||
|
||||
st.metric("Total Portfolio Value",
|
||||
f"${total_portfolio_value:,.2f}",
|
||||
f"${total_paper_pl:,.2f} P/L" if total_paper_pl != 0 else None)
|
||||
|
||||
with col2:
|
||||
# Weekly metrics
|
||||
weekly_pl_pct = (weekly_metrics['weekly_pl'] / total_portfolio_value * 100) if total_portfolio_value > 0 else 0
|
||||
st.metric("Week P/L",
|
||||
f"${weekly_metrics['weekly_pl']:,.2f}",
|
||||
f"{weekly_pl_pct:.2f}% | {weekly_metrics['weekly_trade_count']} trades")
|
||||
|
||||
|
||||
with col3:
|
||||
# Overall P/L metrics (from trade history)
|
||||
total_pl = sum(trade.get('position_pl', 0) for trade in trade_history) if trade_history else 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user