how to run beangrow for this simple case

184 views
Skip to first unread message

Chary Ev2geny

unread,
Mar 19, 2025, 9:03:05 AM3/19/25
to Beancount
Dear all,

I struggling to run beangrow for the following configuration:

Ledger


2019-12-31 open Assets:Cash
2019-12-31 open Equity:Initial-balance
2019-12-31 open Assets:Investments
2019-12-31 open Income:Investments-Gains

2019-12-31 commodity HOO
2019-12-31 commodity USD


2019-12-31 * "Initial balance"
  Assets:Cash                  100 USD
  Equity:Initial-balance      -100 USD

2020-01-01 price HOO 10 USD

2020-01-01 * "Investing"
    Assets:Investments        100  USD
    Assets:Cash              -100  USD

2020-12-31 * "Y2020 accumulated gains from investments"
    Assets:Investments              100 USD
    Income:Investments-Gains       -100 USD


Configuration file


investments {
  investment {
    currency: "USD"
    asset_account: "Assets:Investments"
    cash_accounts: "Assets:Cash"
  }
}


groups {
  group {
    name: "MyInvest"
    investment: "Assets:Investments"
  }
 
}
When I run beangrow, I get the following errors:

C:\_code\py\beangrow>uv run beangrow-returns C:\_code\pytest\beangrouw_exp\test.bean C:\_code\pytest\beangrouw_exp\test.pbtxt C:\_code\pytest\beangrouw_exp\reports
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\_code\py\beangrow\.venv\Scripts\beangrow-returns.exe\__main__.py", line 10, in <module>
  File "C:\_code\py\beangrow\beangrow\compute_returns.py", line 94, in main
    reports.generate_price_pages(account_data_map,
  File "C:\_code\py\beangrow\beangrow\reports.py", line 685, in generate_price_pages
    all_prices = prices.get_all_prices(price_map, base_quote)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\_code\py\beangrow\.venv\Lib\site-packages\beancount\core\prices.py", line 309, in get_all_prices
    return _lookup_price_and_inverse(price_map, base_quote)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\_code\py\beangrow\.venv\Lib\site-packages\beancount\core\prices.py", line 284, in _lookup_price_and_inverse
    return price_map[base_quote]
           ~~~~~~~~~^^^^^^^^^^^^
KeyError: ('USD', 'USD')

Any suggestions how to fix?

Chris Jansen

unread,
Mar 29, 2025, 6:49:06 PM3/29/25
to Beancount

I ran into this myself when I first tried using beangrow. Debugging into the code a bit, I believe the problem is that beangrow doesn't support investments with the "core" currency (i.e. USD). If you look at the example ledger file and config in the beangrow repo, you'll see that all of the configured investments are for a non-USD commodity.

Chary Ev2geny

unread,
Mar 30, 2025, 2:52:52 PM3/30/25
to Beancount
Ok,

thanks for clarification

Julien Stern

unread,
Apr 28, 2025, 10:10:44 AM4/28/25
to Beancount
Maybe this will cause more problems than it solves (I am very unfamiliar with the beangrow code), but I ran into this problem myself and added the following 2 lines to beangrow to make it work.
Hope this helps.
 
    try:
        return price_map[base_quote]
    except KeyError as exc:
        base, quote = base_quote
        # Add this
        if base == quote:
            return [("1970-01-01", 1)];
        # End

        prices = price_map.get((quote, base), None)
        if prices:
            return prices
        else:
            raise

Chary Ev2geny

unread,
Apr 29, 2025, 6:37:08 AM4/29/25
to Beancount
Ok, thanks, let me try
Reply all
Reply to author
Forward
0 new messages