fava icon indicating copy to clipboard operation
fava copied to clipboard

Support for multiple levels of currency conversions

Open leipert opened this issue 3 years ago • 1 comments

I am new to beancount! Thank you for this great visualization tool!

Given a simple beancount file with three commodities: EUR, USD and some imaginary stock called HOOL which is tracked in USD.

option "operating_currency" "EUR"
option "operating_currency" "USD"

2022-01-01 open Equity:Opening-Balances
2022-01-01 open Assets:US:HOOL
2022-01-01 open Assets:Cash

2022-01-30 * "Some stock" ""
  Equity:Opening-Balances -100 HOOL
  Assets:US:HOOL 100 HOOL

2022-01-30 * "Some USD" ""
  Equity:Opening-Balances -100 USD
  Assets:Cash 100 USD

2022-01-28 * "Some EUR" ""
  Equity:Opening-Balances -100 EUR
  Assets:Cash 100 EUR

2022-01-30 price HOOL 100 USD
2022-01-30 price EUR 1.25 USD
2022-02-28 price HOOL 200 USD
2022-02-28 price EUR 1.12 USD

When Converting to USD, both HOOL and EUR are converted, but when converting to EUR, only USD is converted, but not HOOL:

USD EUR
USD EUR

I had a quick look at the source and seems like that beancount.core.convert.convert_position only resolves "one level deep", there is also a beancount.core.convert.convert_amount which supports multiple levels of conversion, but not for positions, but just amounts.

In my mind there are multiple solutions:

  1. Workaround, I could also put HOOL prices in EUR into the DOC
  2. Extend the function on fava side (e.g. by permutating the pricemap, or extending the existing function, e.g. like with get_market_value)

leipert avatar Mar 31 '22 20:03 leipert

It will work if you change it as below. i.e. specify the cost. I can't remember the mechanics of why (presumably the conversion is based on cost and not price) but this is a more realistic entry to have in your journal anyway.

@@ -7,6 +7,6 @@
 
2022-01-30 * "Some stock" ""
   Equity:Opening-Balances -100 HOOL
-  Assets:US:HOOL 100 HOOL
+  Assets:US:HOOL 100 HOOL {1 USD}

carderne avatar Apr 02 '22 16:04 carderne

Even if you add the cost in USD for a HOOL purchase, the report tables will not convert down to EUR even if there is a USD-EUR price quote in the file.

If you use, say, beanprice to automate price quote retrieval, some commodities will not be available in the desired currency through the available APIs. But we could chain multiple conversions.

It would be great to be able to specify HOOL-USD and USD-EUR quotes (fetchable from APIs) and have the reports converted all the way down to the desired currency - EUR in this case.

vascosantos avatar Dec 08 '22 14:12 vascosantos

With #1722, you can now select multiple currencies - the conversions will be performed in sequence

yagebu avatar Jan 20 '24 10:01 yagebu

Thanks, I guess you meant to link #1732!

leipert avatar Jan 21 '24 14:01 leipert