redstreet/fava_investor

Multicurrency support for AA-by-class

redstreet opened this issue · 20 comments

See here.

@scanta2 says:
My ledger file defines two operating currencies, USD and EUR.

Here's the message thrown by fava-investor when using the asset allocation
code.

Error: unable to convert 55.072250 AGGLOBBND to base currency USD (Missing
price directive?)
Error: unable to convert 55.072250 AGGLOBBND to base currency USD (Missing
price directive?)
SystemExit raised: shutting down

The only way AA can assign percentages is to view your entire balance inventory in a single currency, so it can make comparisons. In this case, is the solution to first convert commodities to EUR, then do a second step conversion from EUR to USD? This would depend on being able to convert between the two currencies on or close to the date AA is requested. Let me know.

Also, curious: does beancount/fava support more than two currencies? Is 3+ currencies a common use case?

@scanta2 / @g40matt, minimal beancount sources to reproduce the issue would be helpful. Thanks!

tbm commented

Also, curious: does beancount/fava support more than two currencies? Is 3+ currencies a common use case?

Unfortunately I have 3 operating currencies (my life is complicated). Fava handles this just fine.

tbm commented

Fava has a dropdown menu which lists all your operating currencies. I think that makes sense for fava-investor as well: show my asset allocation for all my EUR investments, for my GBP investmentes, etc.

Fava also has another box "At cost", "Converted to EUR", etc. I think that would also make sense: I could choose "Converted to EUR" to see all my asset allocation in one currency.

Sure, I'm not worried about the UI. Asset allocation requires conversion to a single currency. Which currency and how the conversion is done will affect the results. That needs to be sorted out.

tbm commented

Right, but I thought I explained how I would handle it.

People can choose between their operating currency in one box and the conversion in another. If I choose EUR and "at Cost", do asset allocation for all EUR. if I choose USD and "at Cost", do it for USD. If I choose EUR and "Convert to EUR", I will see the asset allocation of ALL assets converted to EUR (at least those that have a conversion route via pricedb)

I think I see what you're saying now. Your suggestion is to use the UI to address how to do this. I think that could work. But that means he UI aspects need to be ironed out. "At cost" is almost definitely not what the user wants here, and should error out when picked. As should units.

From #56:

I think there are two steps to supporting currency conversion chains:

  1. Look for how Fava converts all to one currency, and hook up the code to use the same thing, including using the UI elements. Note that this has to also work for the library/command line version of the asset allocator, meaning some parameterization is required at least. If there is fava specific code to do the conversion, that can't be used and has to be rewritten. Break up the UI elements so "At Cost" is not an option. Might require changes to fava.

  2. Understand what currency conversion chains mean for asset allocation. Allocations for the same portfolio may vary when using different chains. First, is this truly a problem in practice, or is the variance so small that this is not worth worrying about? If deeper examination is needed, what does this mean for the user?

I don't 100% understand this issue, but I do have the same problem mentioned in the second comment above:

Attaching to ledgers_fava_1
fava_1  | Error: unable to convert 74 XYZ to base currency USD (Missing price directive?)
fava_1  | Error: unable to convert 74 XYZ to base currency USD (Missing price directive?)
fava_1  | SystemExit raised: shutting down
fava_1  | Running Fava on http://0.0.0.0:5000
ledgers_fava_1 exited with code 1

In my case, most of my holdings are in USD, but XYZ is a UK stock, so I have a GBP price directive for it.

So far I've used beancount/fava just fine with separate currency handling (actually three, USD/GBP/EUR, since I'm from the US but live in Europe), so I'm not necessarily expecting a "total overview" that does automagical currency conversion.

Right now, it seems my options to try out fava_investor without it crashing are to remove my XYZ holdings or add a price directive for XYZ/USD, is that accurate? Would a possible (temporary?) solution be to allow setting the currency for fava_investor to be concerned with and ignore commodities in other currencies?

A temporary solution might be to exclude your account with XYZ using the config:

  'asset_alloc_by_class' : {'accounts_patterns': ['Assets:(Investments|Banks)']},

Of course, this would affect your allocation numbers.

If anyone could contribute a few test cases for multicurrency support, I'm happy to work on this.

Some questions for anyone interested in this feature:

  1. Do folks typically specify all their operating currencies as options, like so:
option "operating_currency" "USD"
option "operating_currency" "GBP"

etc.?

  1. How does Fava populate its "Convert to" dropdown list? Does it simply pick all 3-character commodities?

Okay, added multicurrency support. Interested users: please let me know if this works for you.

You will have to list all currencies you use as operating currencies in your beancount file like so:

option "operating_currency" "USD"
option "operating_currency" "GBP"
plugin "beancount.plugins.implicit_prices"  ; Or, include price directives

Note to myself: Ideally, we would automatically figure out the currency to hop via, based on the cost currency of the position. However, currently, cost currency info is not available as a part of the balance tree in libassetalloc.py. Hence, we hop via any available operating currency specified by the user.

cserb commented

Okay, added multicurrency support. Interested users: please let me know if this works for you.

You will have to list all currencies you use as operating currencies in your beancount file like so:

option "operating_currency" "USD"
option "operating_currency" "GBP"

Still having the same issue as mentioned above

❯ investor assetalloc-class ledger.beancount
Error: unable to convert 100 USD to base currency EUR (Missing price directive?)

even though I specified all operating currencies.
Here is how I track the trade:

2022-05-10 * "Convert" #BUY
    Assets:Exchanges:USD  100 USD {0.95 EUR}
    Assets:Exchanges:EUR  -105,2631578947 EUR

Still having the same issue as mentioned above

❯ investor assetalloc-class ledger.beancount
Error: unable to convert 100 USD to base currency EUR (Missing price directive?)

Could you please post a complete, minimal example?

cserb commented

sure:

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

2000-01-01 custom "fava-extension" "fava_investor" "{}"

2012-04-01 open Assets:Exchanges:X:EUR EUR
2012-04-01 open Assets:Exchanges:X:USD USD
2014-01-01 open Income:EUR  EUR

2022-04-13 * "Deposit"
    Income:EUR              -1000 EUR
    Assets:Exchanges:X:EUR  1000 EUR


2022-05-10 * "Convert" #BUY
    Assets:Exchanges:X:EUR  -1502.6321 EUR @@ 1572.1453 USD
    Assets:Exchanges:X:USD

results in:

❯ investor assetalloc-class test.beancount
Error: unable to convert 1572.145300000000000000000000 USD to base currency EUR (Missing price directive?)

Ah, looks like I didn't mention that price directives are required. This line will fix your example:

plugin "beancount.plugins.implicit_prices"