jetpackjules Claude commited on
Commit
13cc81b
·
1 Parent(s): 0ba43cc

Update Investment Performance table columns

Browse files

- Added Sell Price column showing average sell price when positions were sold
- Removed Current Price, Quantity, and Current Value columns for cleaner view
- Streamlined table to focus on key trading metrics: Symbol, Status, IPO/Buy/Sell prices, Investment amount, and P&L

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -351,7 +351,7 @@ def refresh_investment_performance_table():
351
  positions = get_current_positions()
352
 
353
  # Create proper empty DataFrame with correct column names
354
- columns = ['Symbol', 'Status', 'IPO Price', 'Buy Price', 'Current Price', 'Quantity', 'Investment', 'Current Value', 'P&L ($)', 'P&L (%)']
355
 
356
  logger.info(f"Found {len(orders)} total orders for performance analysis")
357
 
@@ -401,8 +401,16 @@ def refresh_investment_performance_table():
401
  # Get IPO price if available
402
  ipo_price = ipo_price_lookup.get(symbol, 0)
403
 
 
 
 
 
 
 
 
 
404
  if current_qty > 0:
405
- # Still holding
406
  status = "🟦 HOLDING"
407
  pos = next((p for p in positions if p['symbol'] == symbol), None)
408
  if pos:
@@ -412,16 +420,13 @@ def refresh_investment_performance_table():
412
  pl_dollars = current_value - investment
413
  pl_percent = (pl_dollars / investment * 100) if investment > 0 else 0
414
  else:
415
- current_price = 0
416
- current_value = 0
417
  investment = current_qty * avg_buy_price
418
  pl_dollars = 0
419
  pl_percent = 0
420
  else:
421
- # Sold all
422
  status = "🟨 SOLD"
423
- current_price = 0
424
- current_value = 0
425
  investment = total_cost
426
  sold_value = sum(float(o.filled_qty or 0) * float(o.filled_avg_price or 0) for o in sell_orders)
427
  pl_dollars = sold_value - investment
@@ -435,10 +440,8 @@ def refresh_investment_performance_table():
435
  'Status': status,
436
  'IPO Price': f"${ipo_price:.2f}" if ipo_price > 0 else 'N/A',
437
  'Buy Price': f"${avg_buy_price:.2f}",
438
- 'Current Price': f"${current_price:.2f}" if current_price > 0 else "N/A",
439
- 'Quantity': f"{current_qty:.0f}",
440
  'Investment': f"${investment:.2f}",
441
- 'Current Value': f"${current_value:.2f}" if current_value > 0 else "N/A",
442
  'P&L ($)': f"${pl_dollars:+.2f}",
443
  'P&L (%)': f"{pl_percent:+.2f}%"
444
  })
 
351
  positions = get_current_positions()
352
 
353
  # Create proper empty DataFrame with correct column names
354
+ columns = ['Symbol', 'Status', 'IPO Price', 'Buy Price', 'Sell Price', 'Investment', 'P&L ($)', 'P&L (%)']
355
 
356
  logger.info(f"Found {len(orders)} total orders for performance analysis")
357
 
 
401
  # Get IPO price if available
402
  ipo_price = ipo_price_lookup.get(symbol, 0)
403
 
404
+ # Calculate sell price (average of all sells)
405
+ if sell_orders:
406
+ avg_sell_price = sum(float(o.filled_qty or 0) * float(o.filled_avg_price or 0) for o in sell_orders) / sum(float(o.filled_qty or 0) for o in sell_orders)
407
+ else:
408
+ avg_sell_price = 0
409
+
410
+ current_qty = total_bought - total_sold
411
+
412
  if current_qty > 0:
413
+ # Still holding - use current position for P&L
414
  status = "🟦 HOLDING"
415
  pos = next((p for p in positions if p['symbol'] == symbol), None)
416
  if pos:
 
420
  pl_dollars = current_value - investment
421
  pl_percent = (pl_dollars / investment * 100) if investment > 0 else 0
422
  else:
423
+ # No current position data
 
424
  investment = current_qty * avg_buy_price
425
  pl_dollars = 0
426
  pl_percent = 0
427
  else:
428
+ # Sold all - calculate realized P&L
429
  status = "🟨 SOLD"
 
 
430
  investment = total_cost
431
  sold_value = sum(float(o.filled_qty or 0) * float(o.filled_avg_price or 0) for o in sell_orders)
432
  pl_dollars = sold_value - investment
 
440
  'Status': status,
441
  'IPO Price': f"${ipo_price:.2f}" if ipo_price > 0 else 'N/A',
442
  'Buy Price': f"${avg_buy_price:.2f}",
443
+ 'Sell Price': f"${avg_sell_price:.2f}" if avg_sell_price > 0 else 'N/A',
 
444
  'Investment': f"${investment:.2f}",
 
445
  'P&L ($)': f"${pl_dollars:+.2f}",
446
  'P&L (%)': f"{pl_percent:+.2f}%"
447
  })