Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculated Balance Assertions #923

Closed
JP-Ellis opened this issue Nov 1, 2018 · 7 comments
Closed

Calculated Balance Assertions #923

JP-Ellis opened this issue Nov 1, 2018 · 7 comments
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. journal The journal file format, and its features.

Comments

@JP-Ellis
Copy link

JP-Ellis commented Nov 1, 2018

In ledger, it is possible to use calculated values for balance assertions, for example:

2018-10-30 * Interest
    Assets:Currency:Bank                             AUD 5.00 = (AUD 200.00 + AUD 1,000.00)
    Income:Interest

which is useful if you have tightly linked accounts. When hledger tries to parse the file, it raises the error:

/home/josh/Finance/finance.ledger:
    |
xxx |     Assets:Currency:Bank                             AUD 5.00 = (AUD 200.00 + AUD 1,000.00)
    |                                                                             ^
unexpected '+'
expecting ';', '{', end of input, newline, or the rest of amount (for a balance assertion or assignment)

Is this expected behaviour from hledger? Or should this be allowed?

@simonmichael
Copy link
Owner

This is expected, we don't support those kind of amount expressions. We are thinking about adding them though, see #871 and related PRs.

@simonmichael simonmichael added journal The journal file format, and its features. A-WISH Some kind of improvement request, hare-brained proposal, or plea. labels Nov 1, 2018
@simonmichael
Copy link
Owner

Related to that, it would be quite useful to hear more details about real-world use cases where this feature is valuable ("tightly linked accounts" ?)

@JP-Ellis
Copy link
Author

JP-Ellis commented Nov 1, 2018

I think it would be a really nice feature to have.


As for the particular real-world use case, here's my situation; I have a bank which provides me with two accounts:

  • A transaction account with no interest, but with a debit card; and,
  • A savings account with high interest, but no debit card.

Every night, money is automatically taken out from the savings account and placed in the transaction account in order to maintain a minimum account balance. I'll also occasionally make manual transfers between these two accounts if I wish to make a larger purchase. As a result, I have a lot of transactions between these two account which I don't really want to keep track of and I really want to treat them as just the one account.

@simonmichael
Copy link
Owner

simonmichael commented Nov 1, 2018 via email

@JP-Ellis
Copy link
Author

JP-Ellis commented Nov 1, 2018

In my case, because I receive statements from both accounts separately. Thus once a month (when interest is paid), I make a balance assertion and sum up the balances from both accounts.

So for the case I gave initially:

2018-10-30 * Interest
    Assets:Currency:Bank                             AUD 5.00 = (AUD 200.00 + AUD 1,000.00)
    Income:Interest

This says that my transaction account has AUD 200.00, while the other account has AUD 1,000.00 for a combined balance of AUD 1,200.00. Of course I could make an annotation instead:

2018-10-30 * Interest
    Assets:Currency:Bank                             AUD 5.00 = AUD 1,200.00 ; AUD 200.00 + AUD 1,000.00
    Income:Interest

Though that feels like I'm just doubling things up.

@JP-Ellis
Copy link
Author

JP-Ellis commented Nov 1, 2018

Furthermore, I can think of one other use-case for having balance assertions in the context of cryptocurrencies.

Specifically, some cryptocurrencies (prefer to) use addresses only once (the sequence addresses are generated according to a seed). This means every time a transaction takes place, the source address is completely emptied and new addresses are created to store the change.

Here's an example:

2018-01-01 * Receive Money
    ; Paid to address 0x1
    ; Balance 0x1: 100
    Assets:Crypto                                          100
    Income:Gifts

2018-01-02 * Receive Money
    ; Paid to address 0x2
    ; Balance 0x1: 100
    ; Balance 0x2: 200
    Assets:Crypto                                          200
    Income:Gifts

2018-01-03 * Give Money
    ; Taken from address 0x1, remaining 70 put into 0x3
    ; Balance 0x1:   0
    ; Balance 0x2: 200
    ; Balance 0x3:  70
    Expenses:Gifts                                          30
    Assets:Crypto

2018-01-04 * Receive Money
    ; Paid to address 0x4
    ; Balance 0x1:   0
    ; Balance 0x2: 200
    ; Balance 0x3:  70
    ; Balance 0x4: 300
    Assets:Crypto                                          300
    Income:Gifts

2018-01-05 * Give Money
    ; Taken from address 0x2, 0x3 and 0x4 remainder placed into 0x5
    ; Balance 0x1:   0
    ; Balance 0x2:   0
    ; Balance 0x3:   0
    ; Balance 0x4:   0
    ; Balance 0x5:  20
    Expenses:Gifts                                         550
    Assets:Crypto

Generally, the clients that manage these transactions will automatically sum up the balances of all the owned addresses, but this still gives a good example of "tightly linked accounts".

@simonmichael
Copy link
Owner

Thanks! I think I got the first one. I haven't yet got the second one. I would say I'm not yet seeing significant pain being caused by not having this feature. Nevertheless, it seems quite possible that we may have it soon. I'll close this in favour of #871.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. journal The journal file format, and its features.
Projects
None yet
Development

No branches or pull requests

2 participants