Roll up Investments panel holdings by security with portfolio weight

Merged
BI
3mo ago
+344-20

Summary

  • Fixes #2291 by rolling up holdings by security across investment accounts in InvestmentStatement#top_holdings / #allocation
  • Weight on the dashboard/reports Investments panel is now % of total portfolio value (including cash), not account-level Holding#weight
  • Each investment appears once; top 5 are ranked by aggregated family-currency value
  • HoldingAllocation duck-types ticker / name / amount_money so existing dashboard and reports views keep working without template changes

Test plan

  • bin/rails test test/models/investment_statement_test.rb
  • Dashboard Investments panel: same ticker in two accounts appears once with combined value
  • Weight reflects share of total portfolio (cash dilutes holding %)
  • Reports investment performance / print top holdings still render

Summary by CodeRabbit

New Features

  • Portfolio Insights
    • Top holdings and portfolio allocation now combine positions in the same security across accounts.
    • Holdings are ranked and weighted using consolidated portfolio values, with fallback handling when portfolio value is unavailable.
    • Allocation percentages remain capped at 100% when negative cash or other adjustments are present.
    • Non-positive holding rows are excluded from reported values, trends, and allocation calculations.
    • Allocation uses cash as the residual.
    • Holding details now include ticker, display name, and monetary value.
    • Trends reflect the selected top holdings using combined account data.