hledger icon indicating copy to clipboard operation
hledger copied to clipboard

Allow auto posting rules based on balance, not just posting amount

Open alerque opened this issue 2 months ago • 1 comments

As far as I understand it the current auto posting system only allows automated amounts as a multiplier of the posting amount. Here is a very rough scenario where this might be used:

# I have money in a savings account
2025-10-01 Opening balance
    Assets:Savings                                  $99,000.00
    Equity

# Somebody gives me money to hand onto, and I leave it in my savings
2025-10-01 PersonA
    Assets:Savings                                  $ 1,000.00
    Liabilities:PersonA

# My bank pays out interest
2025-10-31 Bank payout
    Assets:Savings                                     $360.00
    Income:Interest

# I want to make sure I don't just pocket interest on their capital
= Income:Interest
    Liabilities:PersonA                                  *0.01
    Income:Interest

In this case, what Hledger is going to compute is at auto posting based on a multiplier of the posting amount. I carefully contrived the balances so that the 0.01 multiplier is about right and shows about what I should owe PersonA:

$ hledger reg PersonA --auto
2025-10-02 PersonA               Li::PersonA            $-1,000.00    $-1,000.00
2025-10-04 Bank payout           Li::PersonA                $-3.60    $-1,003.60

Whata I would like to do is use a multiplier of the balance of account Liabilities:PersonA instead, something like this:

= Income:Interest
    Liabilities:PersonA                          (balance*0.0036)
    Income:Interest

Obviously this isn't a perfect pseudo scenario (interest applied over date ranges is complicated) but I think this simple ability to compute a posting value based on the account balance at that date instead of the matching posting value would be quite useful.

alerque avatar Oct 04 '25 22:10 alerque

I can think of several possible syntax options here, for example as show above a keyword could be used, so *N becomes balance*N to toggle this behavior. It could also be =*N or *=N. Another possibility is that an arbitrary account name or query could be used instead.

alerque avatar Oct 04 '25 22:10 alerque