Issue #230: cost of inventory needs to take tolerance rounding into account (blais/beancount)

9 views
Skip to first unread message

Martin Michlmayr

unread,
Mar 10, 2018, 7:42:39 PM3/10/18
to bean...@googlegroups.com
New issue 230: cost of inventory needs to take tolerance rounding into account
https://bitbucket.org/blais/beancount/issues/230/cost-of-inventory-needs-to-take-tolerance

Martin Michlmayr:

Let's say I buy 10.01 of some share (GB00B80QFW04 in this case) at a price of 3.382 GBP each. 10.01 * 3.382 = 33.85382. I'm charged 33.85 GBP for it. Due to inferred_tolerance_default, the transaction balances.

Ok, so we know that I paid 33.85 GBP. Let's repeat this transaction 3 times (as separate transactions). I know I paid 33.85 * 3 = 101.55.

I now sell the 10.01 * 3 for 4.00 GBP each, or 30.03 * 4 = 120.12

I made a gain of 120.12 - 101.55 = 18.57

beancount correctly shows that I spent 101.55 for all purchases (Assets:Cash1 in the example below) and that I gained 120.12 in the sale (Assets:Cash2). But it says that the capital gain was -18.56 rather than -18.57

This is because the cost of the inventory doesn't take into consideration the rounding that took place. There should be some way for this to be taken into account, e.g. through an option that sets a flag. I think bean-count should retain 3.382 as the cost instead of calculating the "true" cost (after rounding) of 33.85 / 10.01 = 3.381618381618382 simply because users should still be able to refer to the lot with 3.382 as the price. But if the flag is set, it should calculate 3.381618381618382 when actually using the cost. (Maybe with an option)

Another approach would be to store both the cost per share and the total cost (i.e. 3.382 per share, but 33.85 as the total rather than 33.85382), but it seems Martin doesn't like this approach. (Personally, I like it.)

BTW, while not the same this is related to issue #194 (about specifying total cost with @@).

Example:

```
option "inferred_tolerance_default" "GBP:0.01"

2018-01-01 open Assets:Investments
2018-01-01 open Assets:Cash1
2018-01-01 open Assets:Cash2
2018-01-01 open Income:CapitalGains

2018-03-08 * "Bought GB00B80QFW04 (HSBC FTSE All Share Index)"
Assets:Investments 10.01 GB00B80QFW04 {3.382 GBP, "lot1"}
Assets:Cash1 -33.85 GBP

2018-03-08 * "Bought GB00B80QFW04 (HSBC FTSE All Share Index)"
Assets:Investments 10.01 GB00B80QFW04 {3.382 GBP, "lot2"}
Assets:Cash1 -33.85 GBP

2018-03-08 * "Bought GB00B80QFW04 (HSBC FTSE All Share Index)"
Assets:Investments 10.01 GB00B80QFW04 {3.382 GBP, "lot3"}
Assets:Cash1 -33.85 GBP

2018-03-10 * "Sold GB00B80QFW04 (HSBC FTSE All Share Index)"
Assets:Investments -30.03 GB00B80QFW04 {3.382 GBP} @ 4.00 GBP
Assets:Cash2 120.12 GBP
Income:CapitalGains
```

bean-query:

```
beancount> SELECT account, units(sum(position)), cost(sum(position)) GROUP BY 1;
account units_sum_p cost_sum_po
------------------- ----------- -----------
Assets:Cash1 -101.55 GBP -101.55 GBP
Assets:Cash2 120.12 GBP 120.12 GBP
Assets:Investments
Income:CapitalGains -18.56 GBP -18.56 GBP
beancount>
```


Reply all
Reply to author
Forward
0 new messages