bean-query with commodity attributes?

147 views
Skip to first unread message

Matt McCormick

unread,
Jan 3, 2024, 7:04:14 AM1/3/24
to Beancount
Hello, I'm a newbie to beancount having transferred over from ledger and trying it out.

Is it possible to use bean-query to filter accounts with commodities where those commodities match a commodity attribute?

For example, I've added attributes to commodities like so to distinguish asset classes:

1970-01-01 commodity FXNAX
name: "FID US BOND IDX"
asset: "bonds"

2011-05-04 commodity FXAIX
name: "FID 500 INDEX"
asset: "stock"

...

I would like to generate a report that provides a breakdown of the current balances in USD for the asset classes ie.

bonds: $250 25%
cash: $100 10%
stock: $650 65%

I have a feeling this may be too advanced for bean-query's syntax.  I'm able to write a Python script if necessary but wanted to see if this would be possible using bean-query first.

Thank you

Patrick Ruckstuhl

unread,
Jan 3, 2024, 8:52:29 AM1/3/24
to bean...@googlegroups.com

Hi,

yes you can do that (at least the amounts, the percentage I don't think so),


  'COMMODITY_META(str)': Get the metadata dict of the commodity directive of the
    currency.

btw. bean-query has a help and help sub commands which are very handy.


Regards,

Patrick

--
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/51c0dce1-2d75-4892-abc4-6ebe9432353en%40googlegroups.com.

Matt McCormick

unread,
Jan 3, 2024, 8:23:24 PM1/3/24
to Beancount
Ah thank you I will try that out.  I was looking for something like "help functions`.  I see the functions are under `help from`

I also came across the Fava Classy Portfolio extension listed in the External Contributions doc which seems very close to what I'm after.  I will give that a try.

Red S

unread,
Jan 4, 2024, 2:38:41 AM1/4/24
to Beancount
Also check out fava_investor and the Asset Allocation extension. It's for the same purpose. However, you can set arbitrary asset classes of arbitrary depths.

See a demo here. The Fava version is broken at the moment due to recent Fava updates, but I'll fix it soon. The command line version works fine (so does the Fava version, except the output rendering and the graph).

Matt McCormick

unread,
Jan 4, 2024, 2:43:36 AM1/4/24
to Beancount
Oh thanks.  It looks like the Fava Classy Portfolio extension has not been maintained and now fails with the current version of Fava.  I managed to fix and get past a couple easy errors but would need to dive into it a bit more to develop enough understanding to fix the current error I'm experiencing.

I'll try out these other extensions.

Matt McCormick

unread,
Jan 4, 2024, 3:00:46 AM1/4/24
to Beancount
I get the error with Fava

Importing module "fava_investor" failed. Error: "cannot import name 'cost_or_value' from 'fava.template_filters' (/home/matt/.local/lib/python3.10/site-packages/fava/template_filters.py)"



It doesn't look like there's been any package update for sometime though.  I assume it's best to just pull the repo and work from that rather than installing from pip?

Matt McCormick

unread,
Jan 4, 2024, 5:01:19 AM1/4/24
to Beancount
I've managed to get it working.  After pulling the repo and using it locally, I needed to add the "beancount.plugins.implicit_prices" plugin and fix all "Warning: skipping negative balance" messages.

Red S

unread,
Jan 4, 2024, 7:24:12 PM1/4/24
to Beancount
Glad you got it working. Thanks for the feedback, added to the README.
Reply all
Reply to author
Forward
0 new messages