simonmichael / hledger

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

Support Ledger-style manual lot matching syntax #1016

Open alensiljak opened 5 years ago

alensiljak commented 5 years ago

In relation to #1015, I'd like to add an issue for the manual lot matching using common stock-trade scenario. In ledger, I'm matching lots explicitly in order to get accurate capital gains calculation and reporting. Note that in the v3.1.3 version of ledger, the full syntax (including the lot purchase price and date) is required in order to make the full match on the lots. This, after the trade, removes them from the list that --lots option provide.

2019-01-05 Opening Balances
    Assets:Cash    1000.00 EUR
    Equity:Opening Balances    -1000.00 EUR

2019-01-10 Buy fund
    Assets:Shares    5 ETF @ 10 EUR
    Assets:Cash    -50 EUR

2019-01-15 Buy more
    Assets:Shares    5 ETF @ 12 EUR
    Assets:Cash    -60 EUR

2019-03-01 Sell
    Assets:Shares    -5 ETF {10 EUR} [2019-01-10] @ 15 EUR
    Assets:Shares    -1 ETF {12 EUR} [2019-01-15] @ 15 EUR
    Assets:Cash    90.00 EUR
    Capital Gains    -28.00 EUR

The reference file-content snippet is here.

Currently, Hledger errors with

   |
17 |     Assets:Shares    -5 ETF {10 EUR} [2019-01-10] @ 15 EUR
   |                              ^
unexpected '1'
expecting '='
simonmichael commented 5 years ago

Thanks for the issues. Going to tweak the names to help me keep track of things..

alensiljak commented 5 years ago

Absolutely. Wish I could be of more help in regards to writing code but it might be a while before I'm in a position to be productive in Haskell.

simonmichael commented 5 years ago

No time like the present! Making small tweaks to an existing project is the quickest way to learn Haskell. #hledger is ready to help.