Strange "Equity:Conversions" mismatch / discrepancy

201 views
Skip to first unread message

Dan Andersson

unread,
May 19, 2025, 7:03:20 AMMay 19
to Beancount
Hi

I'm on Beancount 2.3.6.

First I do this:

  1. Run `bean-query file.beancount`.
  2. Get balance sheet: `SELECT root(account, 2), sum(position)   FROM OPEN ON 2022-08-01 CLOSE ON 2024-01-01 CLEAR   WHERE not account ~ 'Income|Expenses'   GROUP BY 1 ORDER BY 1;`
  3. Get income statement: `SELECT root(account, 2), sum(position)  FROM OPEN ON 2022-08-01 CLOSE ON 2024-01-01  WHERE account ~ 'Income|Expenses'  GROUP BY 1 ORDER BY 1;`
  4. If I sum up everything in the income statement (by copy-pasting everything (they're only base currency amounts) into a separate calculator, and adding everything up), the sum is exactly the `Equity:Earnings` shown in the balance sheet. Great.
  5. If I sum up all `Assets` (there are no `Liabilities`) in the balance sheet (by copy-pasting them into a separate calculator, multiplying non base currency quantities by corresponding base currency cost (in curly braces), and adding everything up), the sum is exactly the `Equity:Earnings` (with sign reversed). Great.
Here is the issue:
  • `Equity:Conversions` is some non-zero amount. Based on how everything already adds up (as I showed above), I was expecting `Equity:Conversions` to be zero.
What could be going on?

Thanks,
DA

Dan Andersson

unread,
May 19, 2025, 2:54:35 PMMay 19
to Beancount
I think I found the culprit.

I started commenting away directives, starting from the end, to find at which point the bogus "Equity:Conversions" (a few dollars) starts showing up.
This occurs immediately after including an entry that looks something like this:

  Assets:EUR    0.000000004 EUR    { 0.84379 USD }
  Expenses:CapitalLoss:EUR    0.000000000004180176 USD

What this is doing is closing down (partially or fully) a EUR lot (which we know exists because Beancount allows me to do it without showing any errors) and booking a loss for this lot. As you can see, very small near-zero amounts.

Could the sudden introduction of the bogus conversion entry (a few dollars) be because of some floating-point calculation issues related to these near-zero amounts? If so, can I increase the precision of this calculation, so I can test if that gets rid of the bogus conversion entry?

Martin Blais

unread,
May 19, 2025, 3:17:55 PMMay 19
to Beancount
Im out of town looking at real estate with little time but
- can you provide a minimal file that reproduces the issue? I can look on the weekend
- the transaction below involves a single currency (IMHO you should not use cost syntax for this)
- beancount does not use floating-point numbers
- imprecise decimal calculations are performed at a specific high precision (IIRC it's the default on the decimal module)


--
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 view this discussion visit https://groups.google.com/d/msgid/beancount/56cf4075-fe8e-47b6-b285-b0fb8d508cb9n%40googlegroups.com.

Dan Andersson

unread,
May 21, 2025, 8:47:10 AMMay 21
to Beancount
Thanks for reply.

I able to fix this issue by avoiding those tiny lots. (When closing a lot and only a tiny amount remains/carries, I make sure to close a tiny bit more/less) Just this caused Beancount to no longer generate that bogus Equity:Conversions entry.

Sorry, but I wasn't able to reproduce in a simple file.

Maybe you can keep this at the back of the mind for the future.

Martin Blais

unread,
May 21, 2025, 3:49:01 PMMay 21
to bean...@googlegroups.com
On Wed, May 21, 2025 at 8:47 AM Dan Andersson <danande...@gmail.com> wrote:
Thanks for reply.

I able to fix this issue by avoiding those tiny lots. (When closing a lot and only a tiny amount remains/carries, I make sure to close a tiny bit more/less) Just this caused Beancount to no longer generate that bogus Equity:Conversions entry.

Just FYI, the entry is not bogus. It is there to make the residual balance perfectly empty in the presence of currency conversions.



Sorry, but I wasn't able to reproduce in a simple file.

Maybe you can keep this at the back of the mind for the future.

Unless you can demonstrate that there is a bug I have to assume it's a case of misunderstanding how the conversion entry gets generated.



 

Dan Andersson

unread,
May 26, 2025, 3:43:02 AMMay 26
to Beancount
Unless you can demonstrate that there is a bug I have to assume it's a case of misunderstanding how the conversion entry gets generated.

I was able to replicate the bug elsewhere. I can't share whole file because info might be sensitive, but I can now show you how I reproduce the problem:

Running:

bean-query debug.beancount \
    "SELECT root(account, 2), cost(sum(position)) \

    FROM OPEN ON 2022-08-01 CLOSE ON 2024-01-01 CLEAR \
    WHERE not account ~ 'Income|Expenses' \
    GROUP BY 1 ORDER BY 1;" | grep '[^ ]$'

gives me this:

Assets:SomeAsset1           9.28888 USD
Assets:SomeAsset2         -29.78513 USD
Assets:SomeAsset3       -5500.81881 USD
Assets:SomeAsset4        5232.10755 USD
Equity:Conversions         -9.35870 USD
Equity:Earnings           290.93981 USD
Liabilities:Liability1     -1.73230 USD

As you can see (after summing up the numbers), "Equity:Conversions" is bogus (because without it, things already add up to 0).

This is the last line in debug.beancount:

2023-01-03 * ""
  Liabilities:Liabilities:FooLiability    1.1300 EUR    { 0.93638 USD }
  Income:Income3    -0.0005763 USD
  Assets:SomeAsset3    -1.129999999999999 EUR    { 0.93587 USD }

If I modify it to this:

2023-01-03 * ""
  Liabilities:Liabilities:FooLiability    1.1300 EUR    { 0.93638 USD }
  Income:Income3    -0.0005763 USD
  Assets:SomeAsset3    -1.13 EUR    { 0.93587 USD }

I now get the expected balances (i.e. bogus conversions is gone):

Assets:SomeAsset1           9.28888 USD
Assets:SomeAsset2         -29.78513 USD
Assets:SomeAsset3       -5500.81881 USD
Assets:SomeAsset4        5232.10755 USD
Equity:Earnings           290.93981 USD
Liabilities:Liability1     -1.73230 USD

So just some precision stuff causes bogus -9.35870 USD conversions popping up out of nowhere.

Although I can't share the whole file, you can let me know if you want me to e.g. insert print/echo statements in some python files to extract more info (to pinpoint the issue).
 

Martin Blais

unread,
May 26, 2025, 2:32:48 PMMay 26
to bean...@googlegroups.com
Hmm, bean-query is probably rounding for display, so that doesn't prove much.

Here's how you can truly validate that there's a bug:
If you simply sum up all the positions in a single Inventory object in a script it should be empty. 
If it's not empty, there's a bug.




--
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.

Dan Andersson

unread,
Jul 1, 2025, 2:46:08 PMJul 1
to Beancount
Ok, I guess it's not a bug in the conversions themselves like you say. (You wrote the code so you have (given how all else balances 100%) good reasons to say this... I trust you)

However then it must be a display bug/issue in bean-query. Because in the meantime I have already come across numbers from those queries ending with stuff like "...E USD" and "...E- USD". So it can get truncated that way - important info cut out.

Until this get fixed, can you please suggest some hack I can use to increase the display precision in bean-query? Is there some Python file on my Linux system I can modify? (It seems to be a standard beancount installation with bin, lib directories and the python files inside lib)

Dan Andersson

unread,
Jul 14, 2025, 3:43:12 PMJul 14
to Beancount
Anyone looking this up later, this issue is fixed in Beancount 3.1.0
Reply all
Reply to author
Forward
0 new messages