close file in multi-file journal not working properly

18 views
Skip to first unread message

alind sharma

unread,
Sep 30, 2026, 1:46:00 PM (9 days ago) Sep 30
to hledger
Hi,
It looks like I have found a issue in mutl file journal setup when using lots.
PFA the zip attached for reference.

These are three years sample journal files and there corresponding close/open flies. I am generating the close/open files using the scripts. The scripts should be run in order.

'1_create_open_close_2021.sh
2_create_open_close_2022.sh
3_create_open_close_2023.sh

As intended, I get the holdings as zero when i run individual ledger files.
hledger -f ledger_2021.journal holdings --lots
hledger -f ledger_2022.journal holdings --lots
hledger -f ledger_2023.journal holdings --lots

Alls good till here.
But when I try to use all.journal, it gives following error. (Probable reason is that the visibility of RELIANCE shares changes when used individually in 2023 close script and resultant close file of 2023 ledger. . But when using all.journal, those assumptions of genreated 001 lot doesn't hold). I tried to simply the example journal as much as I can. These errors are not there if I put all the entries in a single file, probably because of visiblity of transactinos to hledger engine..
Note: The particular case is from a real world split of RELIANCE into RELIANCE and JIOFIN with dates moved 3 months back to fit in yearly journal for ease in debugging purpose) 

$ hledger -f all.journal holdings                                                                                                                                                    
hledger: Error: /tmp/money/close_2023.journal:1:
1 | 2023-12-31 closing balances  ; clopen:2023_close
  |     assets:cash:sbi_saving                                        -1,00,000.00 ₹                                        = 0.00 ₹
  |     assets:cash:zerodha                                            1,36,317.75 ₹                                        = 0.00 ₹
  |     assets:investments:stocks:{2021-09-20, "0001", 2,170.4364 ₹}         -5 RELIANCE {2021-09-20, "0001", 2,170.4364 ₹}
  |     assets:investments:stocks:{2021-09-20, 106.5636 ₹}                   -5 JIOFIN {2021-09-20, 106.5636 ₹}
  |     assets:investments:stocks:{2021-11-28, "0001", 2,170.4364 ₹}        -10 RELIANCE {2021-11-28, "0001", 2,170.4364 ₹}
  |     assets:investments:stocks:{2021-11-28, 106.5636 ₹}                  -10 JIOFIN {2021-11-28, 106.5636 ₹}
  |     assets:investments:stocks:{2022-11-07, 2,300.00 ₹}                  -15 RELIANCE {2022-11-07, 2,300.00 ₹}
  |     assets:investments:stocks:{2022-12-15, 2,250.00 ₹}                  -30 RELIANCE {2022-12-15, 2,250.00 ₹}
  |     equity:opening/closing balances

Postings were read as: unclassified, unclassified, transfer-from, transfer-from, transfer-from, transfer-from, transfer-from, transfer-from, unclassified.
no lots matching {2021-09-20, "0001", 2,170.4364 ₹} for commodity RELIANCE in account assets:investments:stocks on 2023-12-31
Available lots in this account:
  {2021-09-20, "0004", 2,170.4364 ₹}  5
  {2021-11-28, "0004", 2,170.4364 ₹}  10
  {2022-11-07, "0001", 2,300.00 ₹}  15
  {2022-12-15, "0001", 2,250.00 ₹}  30
  Total: 60 RELIANCE
money.tar.gz

alind sharma

unread,
Sep 30, 2026, 1:46:57 PM (9 days ago) Sep 30
to hledger
Version of hledger used:

hledger 1.99-g431497bc4-20260922, linux-x86_64

Simon Michael

unread,
Sep 30, 2026, 4:41:39 PM (9 days ago) Sep 30
to hle...@googlegroups.com
Hi Alind, thanks for the clear repro. There seems to be two problems:

1. When a closing transaction named a lot only partly (eg without the label hledger generated for it), the right lot was closed but the amount was booked to a separate lot subaccount, leaving wrong balances. Now fixed in main.

2. The labels hledger generates for lots sharing a date (like your demerger lots, which reuse the original purchase dates) can differ depending on which files you read. To work around this for now, give those acquisitions explicit labels, eg 5 RELIANCE {2021-09-20, "demerger"} @@ 10,852.182 ₹, then regenerate the close file. (And use your own distinct labels - not "0001" which hledger might mistake for its own.) This needs a build of main with the fix for 1.

Let me know if the workaround for 2 (explicit labels) is problematic. It may be possible to automate that more, but it adds complexity.

alind sharma

unread,
Sep 30, 2026, 10:31:19 PM (8 days ago) Sep 30
to hledger
Hi Simon.
1. I will try explicit labelling of lots as you suggested. I will wait for the latest build from main to be available in github actions as well to try.
2. The "0001" label mentioned in the post was generated by hledger itself. Somewhere, its getting that and I still think that its visibility issue when hledger is working with individual journal files and all.journal subsuming all journal files. You can try executing the files and have a look at  it. There is no explicit labelling in journal files.

alind sharma

unread,
Sep 30, 2026, 10:42:26 PM (8 days ago) Sep 30
to hledger
Explicit labelling {2021-09-20, "demerger"} solves the problem in my sample repro. I will also try it on actual journal files and will report back if I find any issues. Without explicit labeling, hledger is still having issues running all.journal.
Thanks for the suggestion (and of course for the wounderful hledeger) Simon. 

alind sharma

unread,
Sep 30, 2026, 10:48:23 PM (8 days ago) Sep 30
to hledger
Should it be showing the negative quantities even when I am not giving the -E flag. (without --lots, its working as expected)
hledger -f all.journal holdings --lots

Holdings on 2026-10-01

                                                                  ||       Date   Age         Units   Unit cost       Price           Cost         Value  Weight         UGain  UGain%  RGain    XIRR
==================================================================++==================================================================================================================================
 assets:investments:stocks:{2021-09-20, "0001", 2,277.00 ₹}       || 2021-09-20  5.0y    5 RELIANCE  2,277.00 ₹  1,343.90 ₹    11,385.00 ₹    6,719.50 ₹           -4,665.50 ₹  -41.0%         -10.5%
 assets:investments:stocks:{2021-09-20, "demerger", 106.5636 ₹}   || 2021-09-20  5.0y      5 JIOFIN    106.56 ₹                   532.82 ₹                                                            
 assets:investments:stocks:{2021-09-20, "demerger", 2,170.4364 ₹} || 2021-09-20  5.0y    5 RELIANCE  2,170.44 ₹  1,343.90 ₹    10,852.18 ₹    6,719.50 ₹           -4,132.68 ₹  -38.1%         -13.2%
 assets:investments:stocks:{2021-09-20, 2,277.00 ₹}               || 2021-09-20  5.0y   -5 RELIANCE  2,277.00 ₹  1,343.90 ₹   -11,385.00 ₹   -6,719.50 ₹            4,665.50 ₹  -41.0%                
 assets:investments:stocks:{2021-11-28, "0001", 2,277.00 ₹}       || 2021-11-28  4.8y   10 RELIANCE  2,277.00 ₹  1,343.90 ₹    22,770.00 ₹   13,439.00 ₹           -9,331.00 ₹  -41.0%         -10.5%
 assets:investments:stocks:{2021-11-28, "demerger", 106.5636 ₹}   || 2021-11-28  4.8y     10 JIOFIN    106.56 ₹                 1,065.64 ₹                                                            
 assets:investments:stocks:{2021-11-28, "demerger", 2,170.4364 ₹} || 2021-11-28  4.8y   10 RELIANCE  2,170.44 ₹  1,343.90 ₹    21,704.36 ₹   13,439.00 ₹           -8,265.36 ₹  -38.1%         -13.2%
 assets:investments:stocks:{2021-11-28, 2,277.00 ₹}               || 2021-11-28  4.8y  -10 RELIANCE  2,277.00 ₹  1,343.90 ₹   -22,770.00 ₹  -13,439.00 ₹            9,331.00 ₹  -41.0%                
 assets:investments:stocks:{2022-11-07, "0001", 2,300.00 ₹}       || 2022-11-07  3.9y   15 RELIANCE  2,300.00 ₹  1,343.90 ₹    34,500.00 ₹   20,158.50 ₹          -14,341.50 ₹  -41.6%         -13.4%
 assets:investments:stocks:{2022-12-15, "0001", 2,250.00 ₹}       || 2022-12-15  3.8y   30 RELIANCE  2,250.00 ₹  1,343.90 ₹    67,500.00 ₹   40,317.00 ₹          -27,183.00 ₹  -40.3%         -12.8%
------------------------------------------------------------------++----------------------------------------------------------------------------------------------------------------------------------
                                                                  ||                                                         1,36,155.00 ₹                                                  0        

Simon Michael

unread,
Sep 30, 2026, 11:04:39 PM (8 days ago) Sep 30
to hle...@googlegroups.com


On Wed, Sep 30, 2026, at 16:31, alind sharma wrote:
Hi Simon.
1. I will try explicit labelling of lots as you suggested. I will wait for the latest build from main to be available in github actions as well to try.

I have kicked one off at https://github.com/hledgerorg/hledger/actions/runs/36808278128 , if a linux build is helpful.


2. The "0001" label mentioned in the post was generated by hledger itself. Somewhere, its getting that and I still think that its visibility issue when hledger is working with individual journal files and all.journal subsuming all journal files. You can try executing the files and have a look at  it. There is no explicit labelling in journal files.

That's right, and it seems explicit labels are what's needed in this case. The root cause of the problem (or so I believe) is that automatic labels can change if you change which files are being read.

Should it be showing the negative quantities even when I am not giving the -E flag. (without --lots, its working as expected)

Hmm; negative quantities are a bit unexpected. I haven't dug into it in full detail. But see what happens with the new build. It includes support for short lots (as a negative balance in liability accounts); possibly this will make a difference.


Simon Michael

unread,
Sep 30, 2026, 11:19:35 PM (8 days ago) Sep 30
to hle...@googlegroups.com


On Wed, Sep 30, 2026, at 17:04, 'Simon Michael' via hledger wrote:
I have kicked one off at https://github.com/hledgerorg/hledger/actions/runs/36808278128 , if a linux build is helpful.

Or not; this one should produce a binary: https://github.com/hledgerorg/hledger/actions/runs/36809819026

Simon Michael

unread,
Sep 30, 2026, 11:47:27 PM (8 days ago) Sep 30
to hle...@googlegroups.com


On Wed, Sep 30, 2026, at 17:19, 'Simon Michael' via hledger wrote:


On Wed, Sep 30, 2026, at 17:04, 'Simon Michael' via hledger wrote:
I have kicked one off at ... , if a linux build is helpful.

Or not; this one should produce a binary: ...

alind sharma

unread,
Oct 1, 2026, 2:10:06 AM (8 days ago) Oct 1
to hledger
Third time indeed is charm.
And things are working properly with this build. 
With explicit labelling (bonus, splits, merger, demerger), all things are as expected and no negative stocks are visible in holdings report. 
I have converted mine 5 years of journals to lots format and con confirm that "all is well".
Thanks a lot Simon.

Simon Michael

unread,
Oct 1, 2026, 3:35:53 AM (8 days ago) Oct 1
to hle...@googlegroups.com
Excellent! holdings report agreeing with your broker's report ?
--
You received this message because you are subscribed to the Google Groups "hledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hledger+u...@googlegroups.com.

alind sharma

unread,
Oct 1, 2026, 1:37:40 PM (8 days ago) Oct 1
to hledger
Yup.
Holding report matches with broker (Checked quantity and avg price).
I can't comment on xirr as brokerage gives only wrt current holdings and doesn't consider Rgain.
PS: Sorting doesn't work in holdings currently as mentioned in dev docs. Also sorting should be enabled on the user's choice of column as sometimes user wants to sort on invested total value, current total value, xirr etc on a per company basis, I think that these things will come with the stable release anyway.
Reply all
Reply to author
Forward
0 new messages