beangrow icon indicating copy to clipboard operation
beangrow copied to clipboard

Commodity Definition for base currency confuses compute_returns.py

Open cerebore opened this issue 4 years ago • 1 comments

In my beancount file I have this;

1999-12-31 commodity USD
  export: "CASH"
  name: "United States Dollar"

It causes configure.py to produce

  investment {
    currency: "USD"
    asset_account: "Assets:Coinbase:USD"
    cash_accounts: "Assets::Checking"
  }

This in turn confuses compute returns.py during generate_price_pages because it causes a CurrencyPair to exist ('USD', 'USD'):

$ beangrow/beangrow/compute_returns.py xxxxx.beancount config beangrow_output

Traceback (most recent call last):
  File "beangrow/beangrow/compute_returns.py", line 105, in <module>
    main()
  File "beangrow/beangrow/compute_returns.py", line 94, in main
    reports.generate_price_pages(account_data_map,
  File "xxxxx/beangrow/beangrow/reports.py", line 529, in generate_price_pages
    all_prices = prices.get_all_prices(price_map, base_quote)
  File "/usr/local/lib/python3.8/dist-packages/beancount/core/prices.py", line 197, in get_all_prices
    return _lookup_price_and_inverse(price_map, base_quote)
  File "/usr/local/lib/python3.8/dist-packages/beancount/core/prices.py", line 172, in _lookup_price_and_inverse
    return price_map[base_quote]
KeyError: ('USD', 'USD')

cerebore avatar Jun 14 '21 01:06 cerebore

config file produced by configure.py is "suggested" based on your beancount file, but it does not mean it's final and you can and often should adjust it.

in your case (since Coinbase is investment account as i can tell) you have 2 options:

  1. remove currency declaration from Assets:Coinbase:USD making it
investment {
    asset_account: "Assets:Coinbase:USD"
    cash_accounts: "Assets::Checking"
  }

(currency is optional parameter https://github.com/beancount/beangrow/blob/master/beangrow/config.proto)

  1. create different commodity USDCOIN and make it
  investment {
    currency: "USDCOIN"
    asset_account: "Assets:Coinbase:USDCOIN"
    cash_accounts: "Assets::Checking"
  }

As a side note i had similar issue, but in my case account wasn't meant for investment purposes at all: i had Assets:Investments:SQ (SQ commodity) and Assets:Business:CompanyName:SQ (Square account for my business) and that account was wrongly picked up by configure.py, renaming it to Assets:Business:CoName:Square solved the configure.py' confusion.

Basically any account ending with declared commodity code will be picked up by configure.py.

gety9 avatar Sep 13 '21 15:09 gety9