Incorrect gain calculation

67 views
Skip to first unread message

Ismael Bouya

unread,
Oct 19, 2020, 6:53:34 AM10/19/20
to ledge...@googlegroups.com
Hi!
I have this situation in my ledger:
```
2013/11/09 Foo
Broker 3 Foo {10.00 USD} @ 10.00 USD
Dummy

2016/11/09 Foo
Broker 5 Foo {100.00 USD} @ 100.00 USD
Dummy

; Adjust the price to have a mean value of the asset
2017/03/28 Foo
Broker 8 Foo {66.25 USD} @ 66.25 USD
Broker -3 Foo {10.00 USD} @ 10.00 USD
Broker -5 Foo {100.00 USD} @ 100.00 USD

; Move some of this asset somewhere else
2017/03/29 Foo
Other 4 Foo {66.25 USD}
Broker

P 2017/12/04 Foo 1000.00 USD
```

When I want to see the current value in Broker, I can do
$ ledger -f ledger.dat bal -X USD Broker
4000 USD

When I want to see the initial value (=cost?) in Broker, I can do:
$ ledger -f ledger.dat bal -I -X USD Broker
265 USD

From there, I’m looking for a flag that would permit me to get the expected
(unrealized) gain, i.e. 3735 USD

I though that --unrealized would do that, but:
$ ledger -f ~/prive/notes/A_Traiter/Ledger_gain.txt bal --unrealized -X USD Broker
```
4000 USD Broker
-3870 USD Equity:Unrealized Gains
--------------------
130 USD
```

First the value is wrong, then I find no way of getting *only* 3735 USD,
the only way I find to get it is a line in the middle of a balance so I
cannot make use of it...

When I don’t have the 2017/03/29 post, then the --unrealized command
shows a correct information, but I still don’t see how I can obtain only
the unrealized gain.

Any hint?
Kind regards,
--
Ismael
signature.asc

Martin Michlmayr

unread,
Oct 19, 2020, 7:05:15 AM10/19/20
to ledge...@googlegroups.com
I think this is the same as e.g.
https://github.com/ledger/ledger/issues/1821

I seem to recall reading a message from John explaining what ledger is
doing (which is wrong), but I can't find it anymore. :/

IIRC it was something about lots that are removed from an account
still being used to calculate the gain or something.

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

Ismael Bouya

unread,
Oct 20, 2020, 11:13:51 AM10/20/20
to ledge...@googlegroups.com
Hi Martin,
It indeed looks very similar to that issue, thanks!

> IIRC it was something about lots that are removed from an account
> still being used to calculate the gain or something.

I thought of that possibility but I don’t see how the amount I gave in
my example satisfies that hypothesis. Maybe I’m missing something?

--
Ismael
signature.asc

Ismael Bouya

unread,
Oct 20, 2020, 2:46:10 PM10/20/20
to ledge...@googlegroups.com
Hi Martin,
It indeed looks very similar to that issue, thanks!

> IIRC it was something about lots that are removed from an account
> still being used to calculate the gain or something.

signature.asc

Martin Michlmayr

unread,
Nov 2, 2020, 10:18:19 PM11/2/20
to ledge...@googlegroups.com
* Ismael Bouya <ismael....@normalesup.org> [2020-10-20 17:13]:
> > IIRC it was something about lots that are removed from an account
> > still being used to calculate the gain or something.
>
> I thought of that possibility but I don’t see how the amount I gave in
> my example satisfies that hypothesis. Maybe I’m missing something?

As I mentioned, I can't remember the exact details, so I'm not sure.
But I think what I wrote does have some merit.

Look at this:

ledger -f d bal brok --lots
4 Foo {USD66.25} Other
ledger -f d bal other --lots
4 Foo {USD66.25} Other

Which looks good.

But now:

ledger -f d bal broker -B
-4 Foo
USD530 Broker
ledger -f d bal other -B
4 Foo Other

neither of which make sense imho.
Reply all
Reply to author
Forward
0 new messages