Repository navigation
Description
Investment returns view (consume session.returns)
The rustledger WIT component now exposes session.returns (rustledger/rustledger#1849, WIT rustledger:[email protected]) — money-weighted (XIRR) and time-weighted (TWR) returns over the held ledger, computed by the same engine the CLI's rledger report returns uses. This issue is the rustfava side: build the UI that calls it and charts the result, so users get a beangrow-style returns view in the browser.
This is the last piece of Phase 3 of the returns feature (rustledger/rustledger#1847, now closed on the engine side). The data plumbing is done; only the rustfava chart/table remains.
What the component provides
session.returns(investments: list<string>, income: list<string>, currency: string, end-date: string) -> result<returns-result, string>
record returns-result {
cash-flows: u32, // number of dated boundary flows
invested: string, // RAW full-precision decimal strings (like amount.number) —
distributions: string, // NOT display-formatted; the host formats for its locale
current-value: string,
money-weighted: option<f64>, // annualized fraction (0.1 = 10%); none when undefined
time-weighted: option<f64>,
}investments/incomeare account-name prefixes defining the scope (mirroring the CLI's--investments/--income). Money leaving the investment accounts for income/external is a return; an internal transfer is not.currency— pass""to fall back to the ledger's firstoperating_currency.end-date(YYYY-MM-DD) — required (a component has no clock); it's both the horizon and the terminal-valuation date.- Errors:
err(message)on an empty/unparseable end-date, no resolvable reporting currency, an unpriceable flow, or a booking error (the engine is strict-clean: a broken ledger errors rather than reporting an untrustworthy number — surface the message; don't chart over it).
Per-group breakdown (the CLI's --by-group, driven by returns-group: "Name" metadata on open directives) is not a single WIT call yet — the host would call session.returns once per group scope. See rustledger/rustledger#1847 and the returns-group model for the grouping semantics.
Scope of this issue
- Bump the
rustledger-ffi-componentdependency to a build that includessession.returns(WITrustledger:[email protected]). - Add host bindings / a call site for
call_returnson the held session (mirrors the existingsession.queryglue). - A returns view: let the user pick the investment scope (prefixes and/or
returns-groupgroups) + reporting currency + as-of date, callsession.returns, and render the figures (invested / distributions / current value / MWR / TWR) — table first, chart (returns over time / per group) as a follow-up. - Format the raw decimal strings for the locale (they are intentionally unformatted).
- Surface an
err(message)as a clear "can't compute returns — fix the ledger" state rather than a blank/n/achart.
Reference
- The CLI equivalent (
rledger report returns/--by-group) and user docs — seedocs/commands/report.mdin rustledger for the flags, the MWR-vs-TWR explanation, and a worked example. - Prior art the engine follows: beangrow (both metrics, declared groups) and hledger
roi.
Follow-on to rustledger/rustledger#1847 / beancount#1849.
Activity
robcohen commentedon Aug 22, 2026
Unblocked — the capability landed with rustledger v0.22.0.
This was filed against WIT 3.9.0.
mainnow pins v0.22.0, whose component declaresrustledger:[email protected], and it exports the function directly:along with the
returns-resultrecord (cash-flows,invested,distributions,current-value,money-weighted,time-weighted).I confirmed it against the actual pinned artifact rather than the release notes —
wasm-tools component witon the vendoredrustledger_ffi_component-v0.22.0.wasm.Nothing on the rustfava side consumes it yet:
component_engine.pyhas noreturnsbinding (the only matches are docstrings). So the remaining work is exactly what this issue describes — marshal the record and surface the view — with no upstream dependency left.Two things worth knowing before starting:
session.returnsis net-units valuation (cash flows plus market value), not cost basis, and--by-groupresults are independent sub-portfolios that deliberately do not reconcile to a TOTAL.feat: bind session.returns, and fix result<> marshalling it exposed (#…
feat: investment returns report (rustledger#306)