--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/beancount/99181069-9bbc-4edd-b359-655f580a5342%40Spark.
It’s been a while since I looked at this, but IIRC, you’re right in that you’ll have to write a bit of python code. There isn’t a built in function, and what Fava does is the closest reference.
But it should be minor: for each account in the realization, you’ll want to sum up inventories of all its children, and then call convert to convert them to the main currency. Which IIRC is exactly what Fava does.
This prints the balance for the five top level accounts. Easily modified to print it for all the accounts:
#!/usr/bin/env python3 from beancount import loader from beancount.core import realization from beancount.core.realization import compute_balance from beancount.core.convert import convert_position from beancount.core.number import ZERO from beancount.core.prices import build_price_map # 1. Load your file entries, errors, options_map = loader.load_file("main.bc") main_currency = options_map['operating_currency'][0] # 2. Build the realization tree & price map tree = realization.realize(entries) price_map = build_price_map(entries) # 3. For each top‑level account, compute its total (including all sub‑accounts) for acct_name, acct in tree.items(): inv = compute_balance(acct) # Aggregate leaf and branch balances :contentReference[oaicite:0]{index=0} print(f"→ {acct_name!r} has {len(inv)} positions: ") total = ZERO for pos in inv: converted = convert_position(pos, main_currency, price_map) if converted and converted.currency == main_currency: total += converted.number print(f"{acct_name}: {total:.2f} {main_currency}")