Add performance cards and return index chart to portfolio
Fork pre-flight for slot 6 of the portfolio page stack on top of the returns stack (we-promise/sure#5638). Chained by base only: this PR targets the fork copy of the branch below.
Part of #626 (upstream issue we-promise/sure#4748)
What: the portfolio page gets a Performance section (time-weighted return, annualised time-weighted, money-weighted return for the period, annualised money-weighted, volatility, max drawdown) and a Return index chart rebased to 100, both for the picked period and both from one InvestmentStatement#performance per request. Portfolio::Performance#flows_known? (cache version v15) lets the cards say "value return" instead of "time-weighted" when a valuation-tracked account's deposits cannot be removed.
Why: the Overview row shows what the portfolio is worth and how much that moved, but deposits are mixed into every figure. The returns engine already computes flow-adjusted returns; nothing on the page reads them.
Start reading: Portfolio::SectionRegistry#performance, #returns and #index_chart_series, then portfolios/_performance.html.erb; Performance#flows_known? last.
Key tests (test/controllers/portfolios_controller_test.rb, test/models/portfolio/section_registry_test.rb, test/models/portfolio/performance_test.rb, test/system/portfolios_test.rb):
- "the performance section reads every figure from one computation"
- "each return card prints its own figure"
- "the return cards and index caption say time-weighted only when every account's flows are known"
- "the index chart's first point shows no change"
- "flows are known only when no account in the scope is valuation tracked"
- system: "the index chart draws its levels as a line"
Behaviour change: preview features off: nothing changes. On: Performance and Return index appear between Overview and Portfolio value (KEYS = %w[kpis performance index_chart value_chart holdings accounts]). That is for a user with no saved order; with a saved order they are added at the end, as Reports does. A figure that cannot be computed reads "Not enough data", not 0%; a missing rate or a day counted as zero is stated in a DS::Alert. The index chart is hidden below two points. Portfolio::Performance::CACHE_VERSION moves v14 → v15, so cached return metrics are recomputed once. No JavaScript change. No migration.
Size: +276 / −9 outside tests, across 6 files (Ruby, ERB, en/de YAML).
Upstream PR: we-promise/sure#5818, from up/portfolio-performance-section-stacked on we-promise/sure at the same commits (in we-promise/sure's native PR stack 5133).
Screenshots
Same seeded family and period as the KPI PR below (90D; the annualised cards read "Not enough data" because the period is under a year, as their hint says).
| Before (KPI row) | After (this PR) | |
|---|---|---|
| Desktop 1400px | ![]() | ![]() |
| Phone 390px | ![]() | ![]() |
Evidence
Ported onto the returns stack below and the holdings section.
Performance#flows_known?readsreturn_scopes.values.none?(&:valuation_tracked?)insidecompute; both exist on the returns stack, so the method body is unchanged.CACHE_VERSIONgoes to v15, above the stack's v14, and the cache test addsrefute_equal "v14"("v14 entries were cached without flows_known").- Section order and the saved-order tests include
holdings. In the fixture family the index chart is hidden (no account has two balance days in the period), so the rendered order iskpis performance value_chart holdings accounts. - The page's query ceiling goes from 72 to 78: measured 75 with the performance and index sections, which share one
Portfolio::Performance. "does not grow with holdings" still holds.
Blast radius. InvestmentStatement#performance gets its first caller, pinned with expects(:performance).with(period:).once. _kpi_card gains its second caller (rate:), unchanged. time_series_chart_controller.js gains a caller with non-Money values; Series passes them through, and the system test shows the line drawn. Performance#flows_known? is new; index_series's comment now says only recorded flows are removed.
Tests on this branch. Portfolio controller, helper, test/models/portfolio/ and the statement tests: 640 runs, 0 failures. Portfolio and Reports system tests: 19 runs, 0 failures.
Full suite on this branch's head cb035c55e: 19,723 runs, 0 failures, 8 errors, 9 skips. The 8 errors are ReleaseNotesWorkflowTest, which needs node (not in the test image).
Lint: RuboCop 3,664 files, no offenses. erb_lint (862 files): no errors. Brakeman: 0 warnings. Biome lint: no errors; no JavaScript changed.
Checked against AGENTS.md: DS primitives (DS::Alert), functional tokens, icon helper, t() for every string, logic in the registry rather than the views, Minitest only.



