Share Split Decimal Precision

34 views
Skip to first unread message

William Bean

unread,
Mar 14, 2023, 8:01:48 AM3/14/23
to Beancount
I've tried to maintain my dated lots with the recent Vanguard ETF splits. Most of my transactions have no issue resolving, but a few of my reinvested dividends are throwing me balance errors with very small decimal places. Any idea how I can fix this?

2021-12-27 * "Reinvested dividends of VIOV"
  Assets:1-Investments:Trad:IRA:Vanguard:William:VIOV                                      0.381 VIOV {{68.35 USD}}
  Income:2-Nontaxable:TY2021:Investments:Trad:IRA:Vanguard:William:VIOV:Dividend

2023-03-13 * "VIOV share split"
  Assets:1-Investments:Trad:IRA:Vanguard:William:VIOV                                     -0.381 VIOV {{68.35 USD, 2021-12-27}}
  Assets:1-Investments:Trad:IRA:Vanguard:William:VIOV                                      0.762 VIOV {{68.35 USD, 2021-12-27}}

Transaction does not balance: (0.00000000000000000000000002 USD)

Archimedes Smith

unread,
Mar 14, 2023, 10:23:11 AM3/14/23
to Beancount
Looks like the unit cost for each posting happens to be rounded towards different direction. A workaround is to manually adjust the last digit, for example:

2023-03-13 * "VIOV share split"
    Assets:1-Investments:Trad:IRA:Vanguard:William:VIOV     -0.381 VIOV {{68.35 USD, 2021-12-27}}
    Assets:1-Investments:Trad:IRA:Vanguard:William:VIOV      0.762 VIOV {89.69816272965879265091863514 USD, 2021-12-27}

An easier way is to use a plugin for stock split, for example my autobean.stock_split, which does the calculation directly on unit cost and thus suffer less from precision loss. Example:

plugin "autobean.stock_split"
2023-03-13 custom "autobean.stock_split" 2 VIOV  ; 1 -> 2 split
Reply all
Reply to author
Forward
0 new messages