I'm interested in automatically calculating interest payments for
loans (or even for interest paid by the bank into a savings account).
This is for cases where your bank doesn't give you a breakdown of your
repayments. For example if you have a loan for $10,000 and repay $500
every month, it's going to take you more than 20 months to pay it
back!
Following is not ideal:
---snip---
2015/01/01 bank
assets:bank $10,000
liabilities:loan -$10,000
; make a loan repayment
2015/02/01 bank
liabilities:loan
income:salary -$500
; and so on...
---snip---
If you record these payments until your bank says you are done the
`liabilities:loan` account will be positive and would represent the
amount of interest you've paid. But this doesn't feel like proper
accounting.
Let's say you borrow $10,000 and the bank charges you 1.23% interest
every month. If you repay $500 a month and assume the payment comes
just after the interest is calculated the following manual calculation
would be what I expect:
---snip---
2015/01/01 bank
assets:bank $10,000
liabilities:loan -$10,000
2015/02/01 bank
liabilities:loan $377
expenses:interest $123
income:salary -$500
2015/03/01 bank
liabilities:loan $381.64
expenses:interest $118.36
income:salary -$500
; and so on...
---snip---
But this is a little tedious and if it turns out that I've done the
calculation wrong I need to change many lines! It also doesn't
document my understanding of the interest charges (unless I were to
leave many comments).
What does work better, in my opinion, is to define a variable to store
the interest rate and do the interest calculation programmatically
(and elide an amount, why not!). This does what I want and is fairly
easy to understand, but it still has a lot of redundancy. Again, if I
discover later that my calculations are wrong I will have to change
many lines. At least now it's simply a copy and paste job.
---snip---
define interest_rate=(0.0123)
2015/01/01 bank
assets:bank $10,000
liabilities:loan -$10,000
2015/02/01 bank
liabilities:loan
expenses:interest (-(account("liabilities:loan").amount * interest_rate))
income:salary -$500
2015/03/01 bank
liabilities:loan
expenses:interest (-(account("liabilities:loan").amount * interest_rate))
income:salary -$500
2015/04/01 bank
liabilities:loan
expenses:interest (-(account("liabilities:loan").amount * interest_rate))
income:salary -$500
; and so on...
---snip---
Ideally this could be captured in a single automated transaction!
Looking through the mailing list archives suggests this isn't
possible[0][1]. With some help from "afh" in IRC we came up with the
following:
---snip---
define interest_rate=(0.0123)
= Repayment
(Expenses:Interest) (-(account("Liabilities:Loan").total * interest_rate))
(Liabilities:Loan) (amount + (account("Liabilities:Loan").total *
interest_rate))
2015/01/01 Bank Of Ledger
Assets:Checking $10,000.00
[Liabilities:Loan] -$10,000.00
2015/02/01 ACME Inc.
Assets:Checking
Repayment $500.00
2015/03/01 ACME Inc.
Assets:Checking
Repayment $500.00
---snip---
This gets rid of the redundant lines. However the virtual accounts
mean that the correct repayment isn't made to the real "Loan" account
and interest in subsequent months is wrong. By making line 5 a real
account rather than a virtual one the transactions stop balancing.
Perhaps this virtual account automatic transaction could be used as an
aid to calculate the interest which can then be added to the real
transaction manually? The virtual account could then exist to
double-check against the real account.
I'm satisfied with the second example that calculates the interest,
but I'm wondering if any more experienced users can see a more concise
way of performing these calculations in ledger.
Thanks!
0 -
https://groups.google.com/forum/#!searchin/ledger-cli/loan/ledger-cli/tERMoTgxtcU/UrN9TrH-vw8J
1 -
https://groups.google.com/forum/#!searchin/ledger-cli/loan/ledger-cli/VUqvZ-MOpP8/oJ8ohMe4HXgJ