Pad & balance Parent and Child Account: balance failed

66 views
Skip to first unread message

nug get

unread,
Nov 28, 2019, 4:55:04 AM11/28/19
to Beancount
with the following minimal example i get an error on balancing the parent account:  

2000-01-01 open Assets:Parent CHF
2000-01-01 open Assets:Parent:Child CHF
2000-01-01 open Equity:Opening-Balance CHF
2000-01-01 open Expenses:Expenses CHF

;get random amounts on the accounts
2010-01-01 * "initialize"
    Assets:Parent:Child 20 CHF
    Assets:Parent 1 CHF
    Equity:Opening-Balance

; pad child and parent
2010-01-02 pad Assets:Parent:Child Expenses:Expenses
2010-01-03 balance Assets:Parent:Child 0 CHF

2010-01-04 pad Assets:Parent Expenses:Expenses
2010-01-05 balance Assets:Parent 0 CHF


$ bean-check testpad.bean
>testpad.bean:17:      Balance failed for 'Assets:Parent': expected 0 CHF != accumulated -20 CHF (20 too little)
>
>   2010-01-05 balance Assets:Parent                                   0 CHF

I would have expected the parent account to be padded to zero with no error.
removing the pad / balance of the child makes the parent balance correctly.
I do not understand, why does the balancing of the parent account fail?
How would I pad both accounts correctly?
Thanks!



Martin Blais

unread,
Nov 28, 2019, 4:26:51 PM11/28/19
to Beancount
Use
bean-query <filename> print
to view what the padding directive actually does
> --
> You received this message because you are subscribed to the Google Groups "Beancount" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/1312bcca-1a78-470f-be0a-4d4a59bebdae%40googlegroups.com.

c.bo...@gmail.com

unread,
Nov 28, 2019, 7:01:27 PM11/28/19
to Beancount
I am aware that pad just adds the according transaction with the specified account such that the required balance is matched.

now I see
2010-01-01 * "initialize"
 
Assets:Parent:Child      20 CHF
 
Assets:Parent             1
CHF
 
Equity:Opening-Balance  -21 CHF // makes total sense


2010-01-02 pad Assets:Parent:Child Expenses:Expenses

2010-01-02 P "(Padding inserted for Balance of 0 CHF for difference -20 CHF)"
 
Assets:Parent:Child  -20 CHF
 
Expenses:Expenses     20 CHF

2010-01-03 balance Assets:Parent:Child                             0 CHF   // makes total sense


2010-01-04 pad Assets:Parent Expenses:Expenses

2010-01-04 P "(Padding inserted for Balance of 0 CHF for difference -21 CHF)"
 
Assets:Parent      -21 CHF    // makes zero sense, should be -1 (one for the parent plus zero for the child), not -21. This account has a balance of 1, not 21
 
Expenses:Expenses   21 CHF

2010-01-05 balance Assets:Parent                                   0 CHF   ; Diff: -20 CHF  // continues to make zero sense

So i understand that the behavior of pad makes limited sense in nested accounts, hence I try to avoid it.

What would be the clean way of balancing both accounts other than hardcoding a transaction and changing it everytime some historic transactions pops up?
Thanks!
> To unsubscribe from this group and stop receiving emails from it, send an email to bean...@googlegroups.com.

Justus Pendleton

unread,
Nov 28, 2019, 8:54:07 PM11/28/19
to Beancount
On Friday, November 29, 2019 at 7:01:27 AM UTC+7, nugget wrote:
What would be the clean way of balancing both accounts other than hardcoding a transaction and changing it everytime some historic transactions pops up?

I would suggest not to use nested accounts like you have in your example. Don't put transactions in Assets:Parent. In the real world, banks and brokerages generally don't allow accounts to work like in your example. There's a beancount plugin called "leafonly" -- https://aumayr.github.io/beancount-docs-static/api_reference/beancount.plugins.html#module-beancount.plugins.leafonly -- which is how most accounts should be structured, with only rare exceptions.

In any case, dealing with "historic transactions that pop up" is always going to cause problems with balance statements. The solution is to not have historic transactions popping up -- don't write balance statements when you have unknown(?!) outstanding transactions -- or accept that you will need to rewrite your beancount history & transactions. That pad does that automagically for you is not a good thing IMHO.

I think that pad statements should be used very sparingly. They are convenient but a little too magical. You get 99% of the benefit, with no confusion, by simply writing the equivalent pad transaction yourself and making it explicit.

Martin Blais

unread,
Nov 28, 2019, 9:14:37 PM11/28/19
to Beancount
+1
> --
> You received this message because you are subscribed to the Google Groups "Beancount" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to beancount+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/1cc1b693-e310-4e64-8953-28c9f169dcdf%40googlegroups.com.

nug get

unread,
Nov 29, 2019, 4:36:37 AM11/29/19
to Beancount
Thanks Justus,
your answer really puts it into context, which indeed helps me.

nugget

unread,
Nov 29, 2019, 7:18:58 AM11/29/19
to Beancount
Do I find correctly, that the two plugins
"beancount.plugins.unrealized" and
"beancount.plugins.leafonly"

inherently clash since "unrealized" explicitly adds a Child-account to existing (commodity containing) accounts, and "leafonly" will then detect non-leaf accounts with bookings? my Minimal example:
plugin "beancount.plugins.unrealized" "PnL"
plugin "beancount.plugins.leafonly"

1970-01-01 commodity MYSTOCK
    name"MYSTOCK"

2015-11-09 price MYSTOCK          1 USD

1970-01-01 open Assets:USD  USD
1970-01-01 open Assets:MYSTOCK  MYSTOCK

2017-08-04 * "MYSTOCK" "buy MYSTOCK" 
 Assets:MYSTOCK  1 MYSTOCK { 1 USD } 
 Assets:USD

with a query printout

$bean-query test3.bean print
test3
.bean:11:      Non-leaf account 'Assets:MYSTOCK' has postings on it

   
1970-01-01 open Assets:MYSTOCK                                  MYSTOCK


1970-01-01 open Assets:USD                                      USD
1970-01-01 open Assets:MYSTOCK                                  MYSTOCK

1970-01-01 commodity MYSTOCK
  name
: "MYSTOCK"

2015-11-09 price MYSTOCK                                 1 USD

2017-08-04 open Assets:MYSTOCK:PnL
2017-08-04 open Income:MYSTOCK:PnL

2017-08-04 * "MYSTOCK" "buy MYSTOCK"
 
Assets:MYSTOCK   1 MYSTOCK {1 USD, 2017-08-04}
 
Assets:USD      -1 USD                        

2017-08-04 U "Unrealized loss for 1 units of MYSTOCK (price: 1.0000 USD as of 2015-11-09, average cost: 1.0000 USD)"
 
Assets:MYSTOCK:PnL  0 USD
 
Income:MYSTOCK:PnL  0 USD

I really like both plugins, but i cannot imagine combining them. I guess dropping one of them is the only option, or is there a way to use both plugins? For example, specify non-subaccounts for the PnL?
Thanks for your advice!
Reply all
Reply to author
Forward
0 new messages