Ledger doesn't balance capital gains as I'd expect

86 views
Skip to first unread message

Calvin Brizzi

unread,
Jan 18, 2018, 10:16:07 AM1/18/18
to Ledger
So after trying to balance my ledger for way too long, I figured out what the issue was and came up with a minimal file to demonstrate my issue:
 
====================================

2018/01/01 Opening Balances
Assets:EUR                             800 EUR @ 2 USD
Assets:USD                            1000 USD
Equity:Opening Balances

2018/01/05 Transferwise EUR -> USD
Assets:EUR                           -100 EUR {2 USD} @@ 100 USD
Assets:USD                          100 USD
Income:Capital Gains           100 USD

=======================================

But I get an unexpected results when trying to balance:

λ 16:45:00 ~/Documents/personal/ledger/ master* ledger -f test.ledger -X USD bal --unrealized
1800 USD Assets
700 USD EUR
1100 USD USD
-1800 USD Equity
-2600 USD Opening Balances
800 USD Unrealized Losses
100 USD Income:Capital Gains
--------------------
100 USD

Why doesn't it balance? What do I need to do to get it to balance? Am I doing something fundamentally wrong?

Martin Michlmayr

unread,
Jan 18, 2018, 10:38:55 AM1/18/18
to ledge...@googlegroups.com
* Calvin Brizzi <calvin...@gmail.com> [2018-01-18 07:16]:
> 2018/01/01 Opening Balances
> Assets:EUR 800 EUR @ 2 USD
> Assets:USD 1000 USD
> Equity:Opening Balances
>
> 2018/01/05 Transferwise EUR -> USD
> Assets:EUR -100 EUR {2 USD} @@ 100 USD
> Assets:USD 100 USD
> Income:Capital Gains 100 USD

You had 100 EUR at 2 USD, so 200 USD and you're selling it for 100 USD
so surely that's a capital loss and not a capital gain?

--
Martin Michlmayr
http://www.cyrius.com/

Calvin Brizzi

unread,
Jan 18, 2018, 10:49:35 AM1/18/18
to ledge...@googlegroups.com
As far as I know, ledger isn't bothered with names, but to be sure I tested with Capital Loss and not having it in the Income section, with the same result.

--

---
You received this message because you are subscribed to a topic in the Google Groups "Ledger" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ledger-cli/IZ-Skt5FAns/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ledger-cli+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ismael Bouya

unread,
Jan 18, 2018, 10:53:32 AM1/18/18
to ledge...@googlegroups.com
(Thu, Jan 18, 2018 at 10:38:48PM +0700) Martin Michlmayr :
You’re right on an accounting point of view, but is not relevant to the
issue, since ledger doesn’t care about the names of the accounts: it
still remains that the Unrealized Losses should be 700 and not 800 in
the report, since in the end he’s left with 700EUR that he bought at
1400USD and is currently able to sell at 700USD.

I’d say it’s a bug in the software since the rest sounds correct, maybe
it doesn’t take into account the fact that you sold some EUR
When replacing "bal" with "reg", we can see that the <Revalued> account
holds an incorrect amount.


--
Ismael
signature.asc

Martin Michlmayr

unread,
Jan 19, 2018, 2:20:15 AM1/19/18
to ledge...@googlegroups.com
* Calvin Brizzi <calvin...@gmail.com> [2018-01-18 15:49]:
> As far as I know, ledger isn't bothered with names, but to be sure I tested
> with Capital Loss and not having it in the Income section, with the same
> result.

Sorry, I was at the airport when I wrote that email and should have
mentioned that it doesn't actually address the issue you were trying to
point out. I was just trying to understand why you were trying to do
and noticed the strange account name.

Martin Michlmayr

unread,
Jan 19, 2018, 2:27:15 AM1/19/18
to ledge...@googlegroups.com
* Calvin Brizzi <calvin...@gmail.com> [2018-01-18 07:16]:
> λ 16:45:00 ~/Documents/personal/ledger/ master* ledger -f test.ledger -X
> USD bal --unrealized
> 1800 USD Assets
> 700 USD EUR
> 1100 USD USD
> -1800 USD Equity
> -2600 USD Opening Balances
> 800 USD Unrealized Losses
> 100 USD Income:Capital Gains
> --------------------
> 100 USD
>
> Why doesn't it balance? What do I need to do to get it to balance? Am I
> doing something fundamentally wrong?

I don't know why you're getting the result you're getting and whether
it's correct (see the other mail), but in general, only the -B option
is guaranteed to balance in ledger.

Martin Michlmayr

unread,
Jan 19, 2018, 2:27:43 AM1/19/18
to ledge...@googlegroups.com
* Ismael Bouya <ismael....@normalesup.org> [2018-01-18 16:53]:
> You’re right on an accounting point of view, but is not relevant to the
> issue, since ledger doesn’t care about the names of the accounts: it
> still remains that the Unrealized Losses should be 700 and not 800 in
> the report, since in the end he’s left with 700EUR that he bought at
> 1400USD and is currently able to sell at 700USD.

Yeah, that looks incorrect.

Ismael Bouya

unread,
Jan 19, 2018, 3:25:45 AM1/19/18
to ledge...@googlegroups.com
(Fri, Jan 19, 2018 at 02:27:11PM +0700) Martin Michlmayr :
> > Why doesn't it balance? What do I need to do to get it to balance? Am I
> > doing something fundamentally wrong?
>
> I don't know why you're getting the result you're getting and whether
> it's correct (see the other mail), but in general, only the -B option
> is guaranteed to balance in ledger.

+ "--real", and except for rounding errors ;)


Anyway, there was a discussion in the IRC channel yesterday evening, and
it turns out that the error comes from the fact that the revaluing
happens before the transaction.

Thus, the revaluing includes the value of "Income:Capital Gains", which
it shouldn’t. If the revaluing process happened after, it would use the
correct amount (i.e. only the assets that are left).

I tried to have a look at the code to see if I could do a quickwin, but
it’s more complicated than that :/
(Also, there may be another reason why the revaluing happens before and
not after that I’m missing)


Kind regards,
--
Ismael
signature.asc
Reply all
Reply to author
Forward
0 new messages