An unbalanced transaction occurs due to rounding:
chris@MacBook_Air_M2_2022 finance % hledger reg -f investments.ledger
hledger: Error: /Users/chris/investments.ledger:95-102:
95 | 2024-08-16 ! Invested cash
| assets:inv:fidelity:ira 500.903 FDFIX @ $23.74
| assets:inv:fidelity:ira 126.478 FJTDX @ $10.04
| assets:inv:fidelity:ira 431.607 FITFX @ $13.73
| assets:inv:fidelity:ira 60.574 FLXSX @ $15.42
| assets:inv:fidelity:ira 55.964 FLAPX @ $17.90
| assets:inv:fidelity:ira 762.672 FIBUX @ $9.25
| assets:inv:fidelity:ira $-28,077.76
This multi-commodity transaction is unbalanced.
The real postings' sum should be 0 but is: $0.00313
Consider adjusting this entry's amounts, adding missing postings,
or recording conversion price(s) with @, @@ or equity postings.
Check math with python script:
# Commodity Prices
FDFIX = 23.74
FJTDX = 10.04
FITFX = 13.73
FLXSX = 15.42
FLAPX = 17.90
FIBUX = 9.25
# Number of Shares
FDFIX_shares = 500.903
FJTDX_shares = 126.478
FITFX_shares = 431.607
FLXSX_shares = 60.574
FLAPX_shares = 55.964
FIBUX_shares = 762.672
# Total cost of buying shares
T = FDFIX_shares * FDFIX + FJTDX_shares * FJTDX + FITFX_shares * FITFX + FLXSX_shares * FLXSX + FLAPX_shares * FLAPX + FIBUX_shares * FIBUX
print(T)
chris@MacBook_Air_M2_2022 hledger_test % python3 test.py
28077.763130000003
Solution
As Simon has commented below, this problem was solved by setting the Commodity display style as follows:
# Commodity display style
commodity $1,000.00
Interestingly enough, hledger does not return an error when the transaction is isolated into a separate ledger file, even if there is not a commodity display style specified in the journal file.