Skip to content

Investment returns view — consume session.returns (WIT 3.9.0) #263

Closed

Description

@robcohen

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 / income are 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 first operating_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-component dependency to a build that includes session.returns (WIT rustledger:[email protected]).
  • Add host bindings / a call site for call_returns on the held session (mirrors the existing session.query glue).
  • A returns view: let the user pick the investment scope (prefixes and/or returns-group groups) + reporting currency + as-of date, call session.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/a chart.

Reference

  • The CLI equivalent (rledger report returns / --by-group) and user docs — see docs/commands/report.md in 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

  1. robcohen commented on Aug 22, 2026

    @robcohen
    MemberAuthor

    Unblocked — the capability landed with rustledger v0.22.0.

    This was filed against WIT 3.9.0. main now pins v0.22.0, whose component declares rustledger:[email protected], and it exports the function directly:

    returns: func(investments: list<string>, income: list<string>, currency: string, end-date: string)
      -> result<returns-result, string>;

    along with the returns-result record (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 wit on the vendored rustledger_ffi_component-v0.22.0.wasm.

    Nothing on the rustfava side consumes it yet: component_engine.py has no returns binding (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:

    • The v0.21.0 → v0.22.0 WIT change was strictly additive, so adding this binding needs no changes to existing marshalling.
    • session.returns is net-units valuation (cash flows plus market value), not cost basis, and --by-group results are independent sub-portfolios that deliberately do not reconcile to a TOTAL.
  2. added a commit that references this issue on Oct 25, 2026
    eda4988
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions