simonmichael / hledger

Robust, fast, intuitive plain text accounting tool with CLI, TUI and web interfaces.
https://hledger.org
GNU General Public License v3.0
2.94k stars 316 forks source link

Average commodity cost report #1020

Open alensiljak opened 5 years ago

alensiljak commented 5 years ago

Ref: #1015

Something that does not exist out-of-the-box in Ledger but would be very convenient. After implementing the lots feature, and pricing in another commodity (-X), this should be trivial as the value is already "there somewhere". It would need to be output with an appropriate switch.

Effectively, given the data https://gitlab.com/snippets/1856416 one should be able to get an average cost of the commodity in another commodity (currency).

In practice, this means that I want to know that,

This shows the average cost/price per unit for the available lots. The total value is available after --unrealized implementation.

Test case

command b --lots --flat result

          980.00 EUR  Assets:Cash
4 ETF {12.00 EUR} [2019-01-15]  Assets:Shares
          -28.00 EUR  Capital Gains
        -1000.00 EUR  Equity:Opening Balances
--------------------
4 ETF {12.00 EUR} [2019-01-15]
          -48.00 EUR

The remaining 4 ETF lot is from the lot [2019-01-15] and its avg. cost (= original cost in this case) is 12 EUR.

A more complex case would be appropriate for this, to show the average of multiple lots involved.

alensiljak commented 1 year ago

Actually, this does exist in ledger since the later 3.1.x versions.

> ledger b assets and xyz --average-lot-prices
1046 XYZ {2.775 AUD}  Assets:Investments:Shares:XYZ

The average lot price is shown is curly brackets.