beancount/fava and market rates

298 views
Skip to first unread message

Jason Chu

unread,
Dec 7, 2016, 2:14:58 PM12/7/16
to Beancount
Proposal: Add market(self, date) method to Inventory (https://bitbucket.org/blais/beancount/src/c796e5e34b8fbd05862847ff809c1240130c59e0/src/python/beancount/core/inventory.py?at=default&fileviewer=file-view-default#inventory.py-68) and add a switch somewhere in fava to toggle between cost and market values.

Background

Given the discussions in https://github.com/beancount/fava/issues/129 and https://github.com/beancount/fava/issues/242, I think I understand the problem enough to try to explain it.

Right now when we generate balances and charts, we always use the cost of the inventory.  It is apparently the correct accounting method, but it also doesn't change over time.  Currently the way to see commodities at cost is to use something like the unrealized plugin (or my multi-month version of it https://github.com/xentac/beancount-plugins-xentac).  Unfortunately this isn't ideal.

The ideal situation, as Martin points out is to convert to market value at a particular date instead of at cost.  The market method on Inventory would have to take a date upon which to look up the nearest price in the price db.  Perhaps the default could even be today's date, so you could just render everything at today's value if you wanted (would work great for fava balances).

There's one question I have though.  Would I have to create some sort of Equity transaction that balanced out the transactions or is it enough to consider market rates as "magical" value that's added only at display/evaluation time?

I don't mind doing this work, I think I understand the problem well enough to execute it.

Thoughts?

Martin Blais

unread,
Dec 8, 2016, 11:28:38 AM12/8/16
to Beancount
This is where the "weight" of a posting is currently calculated:
https://bitbucket.org/blais/beancount/src/c796e5e34b8fbd05862847ff809c1240130c59e0/src/python/beancount/core/interpolate.py?at=default&fileviewer=file-view-default#interpolate.py-57
A function to compute the market value from an Inventory should be next to it.

I should make a function next to it which accepts a price_map and a date and which computes the market value from it. I'm sure I have two or three versions of this all over, e.g.,
(Note: The concept of Holding will go away at some point, and be replaced with a set of Posting objects, creating Holding was a mistake.)

I'll add a function for you, somewhere in the core. I think the Right Thing I need to do is review the redundant calculations of cost, weight and market value and refactor some things to have a single location where they all are next to each other. That would clean up code. I'll do that.



--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscribe@googlegroups.com.
To post to this group, send email to bean...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/CAFFHUguzenTBz67QsGVOKOP%3DEK3mQ4OXa%2B5gL1MVaVOWC4agUw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Jason Chu

unread,
Dec 21, 2016, 4:37:58 PM12/21/16
to Beancount
Any idea when you'll be able to make these sorts of changes?  Given the holidays, I may have slightly more time to work on the fava side of it if I had a market value method I could use.

I just realized it would also have to be plumbed through bean-query because I also have queries that pull together all my "retirement" savings and give me one number that I'd like to have in market value as well.  That part could wait though.

To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.

Martin Blais

unread,
Dec 21, 2016, 11:59:34 PM12/21/16
to Beancount
I began working on it:

I still need to 
- Test the inventory (using a simple map() call of the new functions to its builder)
- Convert all the old code to these (and make sure everything still works)
- Remove the old code
- Migrate prices to from b.ops to b.core (because this makes use of prices in the core).

The holidays will give me a bit more time as well. I plan to try to finish the two missing documents and hack on some of the loose ends, like this, and issue #145. 



On Wed, Dec 21, 2016 at 4:37 PM, Jason Chu <xen...@gmail.com> wrote:
Any idea when you'll be able to make these sorts of changes?  Given the holidays, I may have slightly more time to work on the fava side of it if I had a market value method I could use.

I just realized it would also have to be plumbed through bean-query because I also have queries that pull together all my "retirement" savings and give me one number that I'd like to have in market value as well.  That part could wait though.

On Thu, Dec 8, 2016 at 8:28 AM Martin Blais <bl...@furius.ca> wrote:
This is where the "weight" of a posting is currently calculated:
https://bitbucket.org/blais/beancount/src/c796e5e34b8fbd05862847ff809c1240130c59e0/src/python/beancount/core/interpolate.py?at=default&fileviewer=file-view-default#interpolate.py-57
A function to compute the market value from an Inventory should be next to it.

I should make a function next to it which accepts a price_map and a date and which computes the market value from it. I'm sure I have two or three versions of this all over, e.g.,
(Note: The concept of Holding will go away at some point, and be replaced with a set of Posting objects, creating Holding was a mistake.)

I'll add a function for you, somewhere in the core. I think the Right Thing I need to do is review the redundant calculations of cost, weight and market value and refactor some things to have a single location where they all are next to each other. That would clean up code. I'll do that.



On Wed, Dec 7, 2016 at 2:14 PM, Jason Chu <xen...@gmail.com> wrote:
Proposal: Add market(self, date) method to Inventory (https://bitbucket.org/blais/beancount/src/c796e5e34b8fbd05862847ff809c1240130c59e0/src/python/beancount/core/inventory.py?at=default&fileviewer=file-view-default#inventory.py-68) and add a switch somewhere in fava to toggle between cost and market values.

Background

Given the discussions in https://github.com/beancount/fava/issues/129 and https://github.com/beancount/fava/issues/242, I think I understand the problem enough to try to explain it.

Right now when we generate balances and charts, we always use the cost of the inventory.  It is apparently the correct accounting method, but it also doesn't change over time.  Currently the way to see commodities at cost is to use something like the unrealized plugin (or my multi-month version of it https://github.com/xentac/beancount-plugins-xentac).  Unfortunately this isn't ideal.

The ideal situation, as Martin points out is to convert to market value at a particular date instead of at cost.  The market method on Inventory would have to take a date upon which to look up the nearest price in the price db.  Perhaps the default could even be today's date, so you could just render everything at today's value if you wanted (would work great for fava balances).

There's one question I have though.  Would I have to create some sort of Equity transaction that balanced out the transactions or is it enough to consider market rates as "magical" value that's added only at display/evaluation time?

I don't mind doing this work, I think I understand the problem well enough to execute it.

Thoughts?

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscribe@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beancount+unsubscribe@googlegroups.com.

To post to this group, send email to bean...@googlegroups.com.

Martin Blais

unread,
Jan 15, 2017, 10:28:22 PM1/15/17
to Beancount
This work has just been merged:
https://bitbucket.org/blais/beancount/commits/99be31c83d04beaa7cf96d727e765b1464b52950

TL;DR:
There's a new module beancount.core.convert with all the conversion functions:
This includes your market value conversion function.

- I've gathered the various other conversion functions from all over the codebase and replaced them with these.
- Inventory does not have specific functions; instead, use Inventory.reduce() with the functions from convert.
- beancount.ops.prices has had to be moved to beancount.core to preserve the dependency tree.
Full gory detail available in the CHANGES file.



Reply all
Reply to author
Forward
0 new messages