beancount / fava

Fava - web interface for Beancount
https://beancount.github.io/fava/
MIT License
1.99k stars 291 forks source link

Support Asset Allocation #947

Closed Mirodin closed 4 years ago

Mirodin commented 5 years ago

I would love for fava to have some kind of support for Asset Allocation with some graphics (i.e. sunburst). A few days ago I asked over on reddit and was told to open an issue to ask for this.

The reddit post for context:

Hey guys,

I switched to Beancount/Fava half a year ago so I am still in early learning phase. However I would like for Fava to show my Asset Allocation (using current prices for my investments, etc.) so I know where I am and what to rebalance.

I know how to create a custom link in Fava's sidebar and use it to show my weekly budget for groceries and such. But I think what I want is a little more involved:

Accounts to use:

Assets:Fixed:Immo:App1 (Risk class 1)

Assets:Fixed:Immo:App1 (Risk class 1)

Assets:Fixed:Annuity (Risk class 1)

Assets:Invest:ETF:Vanguard (Risk class 3)

Assets:Invest:ETF:Dividend (Risk class 3)

I have a few more accounts under Assets:Invest but those are used for trading and not part of my long term allocation.

So my question is: How do I get Fava to combine those Accounts and show me a nice breakdown by risk class and create a sunburst diagram as it does in Trial balance view?

Hope this is not too big of an ask any help would be appreciated!

I think some support for grouping various accounts would be useful for this so one gets a nice chart for group A vs group B. Plus groups would be more generic (I think).

TL;DR; I want fava to show my Asset Allocation across multiple accounts by risk class (or any other grouping) so one can see what is necessary for a rebalancing.

redstreet commented 5 years ago

This has been on my mind too. Here's a proposal:

Input: Commodity (not account) metadata can be used to specify the percentage of each asset class that the holding contains. Eg: a mutual fund may be 85% equities, 15% bonds, which would look like:

2005-01-01 commodity MUTFXX
  asset_class_equity: 85
  asset_class_bonds: 15

What would be awesome is if we could pull this data from somewhere for each commodity, so laborious manual specification can be avoided.

Accounts we want to include in our asset allocation can be tagged with metadata:

1901-01-01 open Assets:Brokerage:XTrade
  asset_allocation_include: True

A validation plugin could check that the asset_class* metadata exist for all commodities in all configured accounts, and add up to a hundred for each commodity, and could optionally add a asset_class_unknown: XX to the remaining.

Reporting: At the top-level, we want a pie-chart showing distribution of the asset classes among the set of configured accounts. Perhaps another chart is tax-adjusted asset allocation. This means each account's expected tax ratio upon withdrawal must also be specified as metadata like so:

1901-01-01 open Assets:Brokerage:XTrade
  expected_taxes_percent: 15

I'm not seeing a need for comparing the asset allocation of groups of accounts. I'd imagine the main use case to be for users wanting to know their total asset allocation.

UI: a simple script can be used to compute and spit out the overall asset allocation, and the asset allocation per account. A fava plugin with the pie charts above would be nice. The ability to graphically display asset allocation for a set of selected accounts would also be useful (eg: checking the percentage of bonds in tax-deferred accounts).

Thoughts/feedback?

Mirodin commented 5 years ago

That sounds very good, I think I like this approach as it is quite flexible in its way of classifying assets.

A validation plugin could check that the asset_class* metadata exist for all commodities in all configured accounts, and add up to a hundred for each commodity, and could optionally add a asset_class_unknown: XX to the remaining.

Unfortunately I have no idea how to write such plugin, my Python got a bit rusty over the last years but I think with documentation I could get this working.

Reporting: At the top-level, we want a pie-chart showing distribution of the asset classes among the set of configured accounts. Perhaps another chart is tax-adjusted asset allocation. This means each account's expected tax ratio upon withdrawal must also be specified as metadata like so:

2005-01-01 commodity MUTFXX
  expected_taxes_percent: 15

If I understand this correctly it is to get the absolut return one will receive upon selling that commodity?

I'm not seeing a need for comparing the asset allocation of groups of accounts. I'd imagine the main use case to be for users wanting to know their total asset allocation.

Well one might have an appartment which I rent out and have a REIT of some sort. For me both are investments in real estate and therefore should somehow be grouped together - but I might miss your point.

UI: a simple script can be used to compute and spit out the overall asset allocation, and the asset allocation per account. A fava plugin with the pie charts above would be nice. The ability to graphically display asset allocation for a set of selected accounts would also be useful (eg: checking the percentage of bonds in tax-deferred accounts).

That sounds great :)

redstreet commented 5 years ago

I'm working on a beancount asset allocation script (text-only) first. I'll post it soon.

redstreet commented 5 years ago

Here you go: https://github.com/redstreet/beancount_asset_allocation

Feel free to test drive that and send me your feedback by opening tickets in that repo.

redstreet commented 5 years ago

BTW, @blais has code for a more generic version of this in the beancount source (beancount/experiments/portfolio). Have you checked that out? It's lacking an example, but it's short and easy to understand if you can read python code.

Also check out this recent thread: https://groups.google.com/forum/#!searchin/beancount/%22asset$20allocation%22|sort:date/beancount/F_pOdotQoxQ/4S4mBUMbAwAJ

The main point there being that exporting raw data to a spreadsheet which calculates your asset allocation is far more powerful than a static script, as it allows you to easily play with "what if" scenarios without having to change code.

Mirodin commented 5 years ago

Awesome, I will give it a try when I get home. Thanks a lot!

seltzered commented 4 years ago

Shameless self-promotion here, but you may want to explore playing with the Fava extension reports feature added earlier this summer - #759 . I have a similar need, but the concern I had was that how someone defines a portfolio may be rather opinionated and impact what conventions (i.e. metadata) are used.

There's now a barebones portfolio example in fava itself - https://github.com/beancount/fava/tree/master/fava/ext/portfolio_list . And I have a very rough prototype of doing something with asset-classes in https://github.com/seltzered/fava-classy-portfolio . Basically visioning people experimenting & prototyping opinionated tools (e.g. asset allocation, budgeting, etc.) as fava extensions before trying to clean-code something for incorporation into fava.

redstreet commented 4 years ago

@seltzered : thank you for the fava extension reports feature. This is super helpful! See my next post.

redstreet commented 4 years ago

@Mirodin and others: an asset allocation script for beancount and extension for fava that supports arbitrary classes and depths is now functional! Check out the fava extension. Simply add any arbitrary metadata starting with asset_allocation_ to a commodity. For example: asset_allocation_equity_domestic_value: 20 , and an asset class tree is computed for you. Sample output:

image

Collapsing the tree works as you would expect: image

redstreet commented 4 years ago

A chart would be nice, and I hope to see one added soon.

Since it's otherwise functional, I'd recommend closing this issue. Feel free to open further issues or feature requests at fava-investor or better yet, contribute there.

seltzered commented 4 years ago

@redstreet Nice work! Saw your messages here and on the mailing list, trying to get through some other tasks to play with this soon!

redstreet commented 2 years ago

An update: this has been in Fava Investor for a while now. See a live demo here.

image