prices & pricedb Reporting Commands

29 views
Skip to first unread message

lipp f

unread,
Oct 16, 2021, 3:05:34 PMOct 16
to Ledger

From https://www.ledger-cli.org/3.0/doc/ledger3.html#Basic-Reporting-Commands:


prices

           Print price history for matching commodities.

pricedb

           Print price history for matching commodities in a format readable by ledger.


My understanding is that these commands are supposed to somehow show records from the price database.


I have tried the following commands

      $ ledger --args-only --price-db prices-db.j -f empty.j pricedb

      $ ledger --args-only --price-db prices-db.j -f empty.j prices

..., eventually followed by a commodity name or a commodity filter like -l 'commodity=~/USD/'and I don't get anything.


Can someone help? A few examples maybe? TIA.

Richard Lawrence

unread,
Oct 17, 2021, 3:47:34 AMOct 17
to lipp f, Ledger
Hi lipp,

lipp f <flip...@gmail.com> writes:

> My understanding is that these commands are supposed to somehow show
> records from the price database.
>
> I have tried the following commands
>
> $ ledger --args-only --price-db prices-db.j -f empty.j pricedb
>
> $ ledger --args-only --price-db prices-db.j -f empty.j prices
>
> ..., eventually followed by a commodity name or a commodity filter like -l
> 'commodity=~/USD/'and I don't get anything.

I suspect this is because you are using an empty journal file (based on
the name you've given here). Is that the case?

These commands work fine for me if I use my regular journal file. If I
use an empty one, I get no output.

I'm not sure what you'd expect ledger to report for an empty journal
file, since there are no transactions from which prices can be
calculated. (Are you just expecting it to echo your prices-db.j? If so,
I'd recommend a different command for that ;)

--
Best,
Richard

lipp f

unread,
Oct 17, 2021, 8:16:32 AMOct 17
to Ledger
Thank you for your answer  Richard. For me, it makes no difference if I use a real jurnal or an empty one. Absolutely nothing on the screen.

Can you please explain what each command does and how are they different? Maybe to show how you run them, what parameters are you using and what the output is?

Richard Lawrence

unread,
Oct 19, 2021, 4:41:18 AMOct 19
to lipp f, Ledger
Hi lipp,

lipp f <flip...@gmail.com> writes:

> Thank you for your answer Richard. For me, it makes no difference if I use
> a real jurnal or an empty one. Absolutely nothing on the screen.
>
> Can you please explain what each command does and how are they different?
> Maybe to show how you run them, what parameters are you using and what the
> output is?

The command 'ledger pricedb' outputs prices in a format that can be read
back in by ledger, like:

P 2021/09/29 00:00:00 VBTLX $11.269182911655
P 2021/10/04 00:00:00 VBTLX $11.29
P 2021/10/11 00:00:00 VBTLX $11.19
P 2021/10/18 00:00:00 VBTLX $11.24

'ledger prices' basically outputs the same information but not in the
format of a ledger price declaration, and only one price per day, like:

2021/09/29 VBTLX $11.269182911655
2021/10/04 VBTLX $11.29
2021/10/11 VBTLX $11.19
2021/10/18 VBTLX $11.24

As you can see, there is very little difference here in my case (VBTLX
has a price at most once a day anyway) but the pricedb format above
starts with "P" and has a slot for the seconds. Note also that both
commands output prices calculated by ledger (the first line in both
cases), as well as those explicitly recorded in the price database.

The entries in my prices.db file, which I just include in my main ledger
file with the line

include prices.db

look like this:

P 2021/10/18 VBTLX $11.24

(I have a custom script that I use to fetch these periodically and
append them to the prices.db file.)

Thus, both of these commands require specifying the ledger file, which I
do implicitly via the LEDGER_FILE environment variable, but you can do
explicitly with e.g.

ledger -f path/to/file prices
ledger -f path/to/file pricedb

and the price declarations are then pulled in from the separate
prices.db file via the include line.

Of course, there are transactions involving these commodities in my main
ledger file, which look like

2021/09/29 * Broker
assets:Retirement:Roth IRA 10.0000 VBTLX @@ $112.69
revenues:Investments:Dividends -$112.69

Again, without any transactions that actually the commodities which have
prices, you probably won't see any output.

So that's my setup. Does that help?

--
Best,
Richard
Reply all
Reply to author
Forward
0 new messages