See average cost of commodity

109 views
Skip to first unread message

nagis...@gmail.com

unread,
Mar 26, 2020, 9:53:31 AM3/26/20
to Ledger
Hi,

Is there a way to see average cost of a commodity? It would be nice to know the average cost of stocks purchased over a period of time.

For example, with the following lots,

3 ABC {$100} [20-Mar-25]
6 ABC {$200} [20-Mar-19]

I want to see something like:

ABC $166

I have played around with value expressions for --total, but can't really figure it out.

Thanks
Harish

Martin Michlmayr

unread,
Mar 26, 2020, 10:29:18 AM3/26/20
to ledge...@googlegroups.com
* nagis...@gmail.com <nagis...@gmail.com> [2020-03-25 23:33]:
> I want to see something like:
>
> ABC $166

John implemented --average-lot-prices recently, but you need ledger
from Git.

ledger -f d bal inv --average-lot-prices
9 ABC {$166.666667} assets:investments

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

John Wiegley

unread,
Mar 26, 2020, 5:32:58 PM3/26/20
to Martin Michlmayr, ledge...@googlegroups.com
>>>>> "MM" == Martin Michlmayr <t...@cyrius.com> writes:

MM> John implemented --average-lot-prices recently, but you need ledger from
MM> Git.

Yes, given that I recently discovered that I also need a --plopen, I'm now
realizing that both average lot prices and P/L Open are instances of the same
thing: Transforming an aggregate balance according to a formula. There should
be a way of generalizing this so that it becomes easy for others to apply
their own transformations.

I.e., a balance reduction is a function from balance -> balance that applies
some calculation to each entry in the balance based on information gleaned
from the whole balance. Since the value expression language in Ledger doesn't
really deal very well with lists or arrays, C++ is still the easiest language
to write such transformations in.

John
Reply all
Reply to author
Forward
0 new messages