Net worth over time examples?

467 views
Skip to first unread message

Aaron Stacy

unread,
Feb 14, 2021, 10:46:44 AM2/14/21
to bean...@googlegroups.com
Hi all, my I’ve seen some references to net worth over time scripts/queries, but I’m having trouble finding specifics. Anyone have quick links to share? Thanks!

Stefano Zacchiroli

unread,
Feb 14, 2021, 11:26:00 AM2/14/21
to bean...@googlegroups.com
I don't have a script ready to share for this... but that's because
you've net worth over time readily available in Fava, and that's what I
use. You can see it in action on the live Fava demo here:

https://fava.pythonanywhere.com/example-beancount-file/balance_sheet/

Does that address your need?

I'm not sure if it's possible to obtain the same result in tabular form
with just BQL (because you can't add/subtract columns to generate other
columns, IIRC), but it should be trivial to script from the output of a
BQL query that returns Assets and Liabilities GROUP-ed BY the
periodicity you want.

Cheers
--
Stefano Zacchiroli . za...@upsilon.cc . upsilon.cc/zack . . o . . . o . o
Computer Science Professor . CTO Software Heritage . . . . . o . . . o o
Former Debian Project Leader & OSI Board Director . . . o o o . . . o .
« the first rule of tautology club is the first rule of tautology club »

Aaron Stacy

unread,
Feb 14, 2021, 3:00:44 PM2/14/21
to bean...@googlegroups.com
For example, this query is useful:

    SELECT date, flag, description, account, units(position), units(balance)

But it loses the information for the balance of each account (i.e. are the shares of Vanguard 2050 target retirement fund in my 401k or IRA?), which would be nice for a stacked area chart to visualize both the sum across accounts over time as well as individual account balances.

It seems like maybe calling beancount.loader.load_file, and then iterating over the transactions with an inventory object for each account may be the way to go.

Aaron Stacy

unread,
Feb 14, 2021, 3:45:44 PM2/14/21
to bean...@googlegroups.com
OK after reading the Inventory class docs, I think I've got words for my issue -- the query's balance is a single inventory for all accounts, and I'd like an inventory per account.

I think if I just want a csv I can export to a stacked area chart in a spreadsheet, I can do something like:

inventories = defaultdict(lambda: Inventory())
for directive in beancount.loader.load_file(...):
  if isinstance(directive, Transaction) and asset_leg(directive) is not None:
    inventories[asset_leg(directive).account].add_position(asset_leg(directive).position)
    print_line(inventories)

Martin Blais

unread,
Feb 14, 2021, 10:50:38 PM2/14/21
to Beancount
Here's the script:
https://github.com/beancount/beanlabs/blob/master/beanlabs/compensation/net-worth-over-time.py

- It's not sufficient to add to an inventory because you'll need to convert to market value
- Furthermore, one needs to convert all market values to a single currency.
The script does that.

In the new (v3) version, I will make the Python API take a more prominent space with developer documentation specific to how to accomplish various tasks with an Inventory (there are some details which aren't entirely obvious, especially around market value conversions).





--
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 on the web visit https://groups.google.com/d/msgid/beancount/CACjABkm%3DiFsZwwr-fUJVnCSxWfKG4QU18PTfWJskSJrPrApQgA%40mail.gmail.com.

Kylie Jeñner

unread,
Apr 1, 2025, 7:45:17 AM4/1/25
to Beancount
  Great content! I appreciate the insights shared. Keep up the amazing work and efforts.  
Reply all
Reply to author
Forward
0 new messages