Possible bug in --market interaction with --end

28 views
Skip to first unread message

Richard M Kreuter

unread,
Jan 13, 2022, 11:11:45 AM1/13/22
to ledge...@googlegroups.com
Hello,

Is the following behavior a bug?

Given the leger file at /tmp/foo.ledger containing exactly

--
2022-01-01 * Buy FOO
Assets:Brokerage 10 FOO @ $1.00
Assets:Cash $-10.00

P 2022-01-02 23:59:00 FOO $2.00

2022-01-03 * Buy more FOO
Assets:Brokerage 2.5 FOO @ $4.00
Income:Cash $-10.00
--

and these environment settings

--
$ export LEDGER_FILE=/tmp/foo.ledger
$ export LEDGER_PAGER=cat
--

I find that a balance report with an --end option produces these
outputs, varying only whether the --market option is used:

--
$ ledger --end 2022-01-03 bal --balance-format '%A\t%t\n' /Brokerage/
Assets:Brokerage 10.0 FOO
$ ledger --market --end 2022-01-03 bal --balance-format '%A\t%t\n' /Brokerage/
Assets:Brokerage $40.00
--

The first invocation ignores the 2.5 FOO from the posting on 2022-01-03,
but the second seems to use the price in that posting. That is, the
--end date appears to act as an upper exclusive bound for the purpose of
summing postings, but seemingly not as an exclusive bound for price db
lookup involved in calculating market value.

[If this somehow isn't a bug, it looks like one workaround is to use (@)
and (@@) instead of @ or @@ in postings. That's good enough for my
needs, I think.]

In case it matters, I'm using this version of Ledger:

--
$ ledger --version
Ledger 3.2.1-20200518, the command-line accounting tool

Copyright (c) 2003-2019, John Wiegley. All rights reserved.

This program is made available under the terms of the BSD Public License.
See LICENSE file included with the distribution for details and disclaimer.
--

Thanks,
Richard

Martin Michlmayr

unread,
Jan 13, 2022, 6:37:12 PM1/13/22
to ledge...@googlegroups.com
* Richard M Kreuter <kre...@progn.net> [2022-01-13 08:48]:
> Is the following behavior a bug?

No.

> That is, the --end date appears to act as an upper exclusive bound
> for the purpose of summing postings, but seemingly not as an
> exclusive bound for price db lookup involved in calculating market
> value.

--end stops evaluating transactions, but things are still evaluated as
of the _current_ date, including pricedb entries after the end of
--end.

What you want is --now (maybe in combination with --end) which
specifies when to value things.

(Note that --end is exclusive whereas --now is inclusive, i.e. --end
stops one day before --end; --now is on the date of --now)

I use this command for value my investments at the end of the year:

-p "until 2021-01-01" --now 2020-12-31 bal --price-db pricedb/funds.pricedb -V

--
Martin Michlmayr
https://www.cyrius.com/
Reply all
Reply to author
Forward
0 new messages