Flag an opening short of unpriced journalled-out units #5985
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #5985"
general
weight: 0.35
jaysbeekay
Closes #5982
Fork pre-flight: jaysbeekay/sure#1040 (same commits: same branch, same head).
Stacked on #5966 (
up/daily-returns-opening-holdings), which carries the opening logic this extends.Summary
An account whose first balance row opens with nothing in
start_non_cash_balancevalues what it held at the open as the units at the close less the units traded that day (#5966). A journal out with nothing to price it that day counts in those traded units but adds no value: either the security has no holdings row and the trade has no price, or the holdings row is priced at 0 (whatHolding::ForwardCalculatorwrites when the journal's zero is the day's only price). The opening came out short and nothing said so:Portfolio::DailyReturns: when the journal is internal,contribution_journal_unpricedstayed false, so the net contributions line showed no "may be incomplete" note.InvestmentStatement#period_return_trend: the Period return KPI kept the account andperiod_return_unconvertible_countstayed 0. With a zero-priced row, it also valued a same-day sale at 0 and read its proceeds as a gain (10,750 where 10,200 is right in the test below).Now both readers mark these openings. DailyReturns raises
contribution_journal_unpricedon the opening's row. InvestmentStatement leaves the account out of both period-return legs and counts it in a newperiod_return_unpriced_count, and the Period return hint names that reason apart from "no exchange rate".What changed
app/models/portfolio/daily_returns.rb:flows_by_account_dategainstraded_unpriced, for a journal out with(no holdings row AND no price on the trade AND the day's net units in the security sold) OR a holdings row priced at <= 0.openings_by_datecarries it asopening_journal_unpriced, and the final SELECT ORs it intocontribution_journal_unpriced.rate_missingand suppression are unchanged.app/models/investment_statement.rb:-
period_return_opening_trades_sqlgains anunpriced_journalcolumn, the same predicate written on its own aliases. Its other readers select named columns and are unchanged.- New
period_return_unpriced_journal_account_ids, whichperiod_return_trendsubtracts beside the unconvertible ids.- New
period_return_unpriced_count, which leaves out accountsperiod_return_unconvertible_countalready counts, so no account is named twice.app/models/portfolio/section_registry.rb: aperiod_return_unpricedKPI.app/helpers/portfolios_helper.rb:kpi_hinttakes an optional third count. The other cards don't pass it.app/views/portfolios/_kpi_row.html.erb: the Period return card passes the count.config/locales/views/portfolios/en.ymlandde.yml:unpriced_journal_accounts.Portfolio::Performancecaches itsmetricshash and no metric readscontribution_journal_unpriced. The Reports body markup is unchanged.Non-test diff: +72 / −15.
Screenshots
The Portfolio page, last 30 days. Account A goes from 10,000 to 10,200. Account B's first row sells 5 at 110 and journals 5 out at price 0, leaving a holdings row at qty 0 priced at 0.
| | Light | Dark |
|---|---|---|
| Before (306e511d7): $750.00 (7.5%), no note | !before light | !before dark |
| After: $200.00 (2.0%), "excludes 1 account with an unpriced transfer out" | !after light | !after dark |
The after shots were taken on 6660d9bb9. f86118add changes only a journal priced on the trade and the double count, and neither applies to this setup (journal at price 0, every account converts), so the output on the pushed head is the same.
Tests
| Test | Before fix |
|---|---|
| DailyReturns "an internal zero-priced journal out with no holdings row on an arrival's first row makes contributions incomplete" |
Expected false to be truthy|| DailyReturns "an internal zero-priced journal out with a holdings row at price 0 on an arrival's first row makes contributions incomplete" |
Expected false to be truthy|| DailyReturns "an internal zero-priced journal out of a whole position at price 0 on an arrival's first row makes contributions incomplete" |
Expected false to be truthy|| DailyReturns "an internal journal out priced on the trade with a holdings row at price 0 on an arrival's first row makes contributions incomplete" |
Expected false to be truthy|| InvestmentStatement "period_return_trend leaves out an account whose first row journals out units at a zero-priced holding" |
Expected: 10200 Actual: 10750|| InvestmentStatement "period_return_trend leaves out an account whose first row journals out unpriced units with no holdings row" |
Expected: 10200 Actual: 10250|| InvestmentStatement "period_return_trend leaves out an account whose first row journals out priced units at a zero-priced holding" |
Expected: 10200 Actual: 10750|| InvestmentStatement "period_return_unpriced_count leaves out an account already counted as unconvertible" |
Expected: 0 Actual: 1|Negative cases, which pass before and after, in both readers:
The existing "keeps an account whose first-row traded units are worth nothing" now also asserts the new count is 0. An agreement test runs both readers over six shapes and asserts they decide alike: no row, a row at 0, a row at 110, net bought, priced on the trade, and priced on the trade with a row at 0. Helper tests cover the hint in en and de, and the registry test covers the new KPI key.
Mutations, one term at a time, each caught by a named test in each reader: the
<= 0arm, the Transfer label, the trade-price term (dropped, or applied to both arms),net_qty < 0,qty < 0, the OR intocontribution_journal_unpriced, the subtraction inperiod_return_trend, and the subtraction in the count.Verification:
ReleaseNotesWorkflowTest, which needsnode, missing from the local test image. Rubocop, erb_lint, Brakeman and Biome were all clean.investment_statement.rband three of the test files above. It has been verified by CI only (green on the fork pre-flight), not by a local full-suite run.Known limits
period_return_trendtoo. An affected account drops out of it without a note, as an unconvertible one already does. It gets no hint here.<!-- This is an auto-generated description by cubic. -->
---
Summary by cubic
Flags accounts whose opening value is short of units journalled out with no price, so the figure is no longer silently understated.
Portfolio::DailyReturnsnow raisescontribution_journal_unpricedwhen an internal journal out on an account's first row has no usable price that day, and the Period return KPI inInvestmentStatementexcludes such accounts and names the reason in its hint. Previously an internal journal stayed unflagged, and a zero-priced holdings row also caused a same-day sale's proceeds to be read as a gain.Portfolio::DailyReturns.unpriced_journal_out_sql, built on a singlejournal_sqldefinition of a security journal.<sup>Written for commit d33604f0dde66048f7f6229830def0a6dd780c71. Summary will update on new commits.</sup>
<a href="https://cubic.dev/pr/we-promise/sure/pull/5985?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="View guided diff" src="https://www.cubic.dev/buttons/review-in-cubic-light.svg"></picture></a> <a href="https://www.cubic.dev/action/auto-fix/pr/we-promise/sure/5985?returnTo=https%3A%2F%2Fgithub.com%2Fwe-promise%2Fsure%2Fpull%2F5985&source=description" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"><img alt="Turn on auto-fix" src="https://www.cubic.dev/buttons/turn-on-auto-fix-light.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
New Features
Period-return figures now exclude accounts with unpriced transfers that make their opening values unknown. The KPI hint reports how many accounts were excluded, alongside any accounts lacking a currency conversion rate.
* Contribution completeness now reflects unpriced outgoing transfers, helping identify when transfer values leave account performance figures uncertain. Known transfer prices and offsetting purchases continue to be reflected in contribution calculations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->