Skip to content
Dmitry Astapov edited this page Oct 10, 2024 · 14 revisions

Associated directory: 08-mortgage

Where is the complexity

When you take out a mortgage (or any other loan) you usually set up a periodic repayment plan.

Then you make payments (manually, or by setting up payment instructions with your bank) and they usually could be seen in your bank account statement.

However, each payment consists of interest payment (this is your bank service fee, essentially) and capital payment (which offsets the body of your loan). In my experience, statements from mortgage provider are either unparseable, do not provide a breakdown, or are being supplied too infrequently (quarterly or yearly) or all of the above.

However, it is possible to compute breakdown yourself, using hledger-interest.

This way, you would import mortgage payments from your bank statement as going into liabilities:mortgage, and then hledger-interest will generate additional transactions which will move your interest payments out of liabilities:mortgage and into expenses:mortgage interest.

Taking out a mortgage

If you took a mortgage to buy a house costing X, putting down Y yourself, taking a loan for X-Y and paying various fees in the amount of Z (which get rolled into the mortgage amount), then this could be recorded as:

YYYY-MM-DD  Taking out the mortgage
  assets:bank           -Y
  liabilities:mortgage
  assets:house          X
  expenses:fees         Z

Let's say that in our example house will cost £1000, downpayment is £150 and fees are £5, so our principal is going to be £1000-£150+£5=£855, and it is going to be lent to us with interest rate of 2%:

$ hledger -f all.journal print liabilities:mortgage 'desc:Taking'

2014-01-02 Taking out mortgage to buy a house for £1000 (£150 downpayment, £5 opening fee, included in mortgage, 2% rate)
    assets:cash                     £-150
    expenses:mortage fees              £5
    liabilities:mortgage
    assets:house                    £1000

Computing capital payments

Let's say that mortgage payments come out of your primary bank account and you record them as coming into liabilities:mortgage, like this:

$ hledger -f all.journal print 'liabilities:mortgage' 'payee:HSBC'

2014-03-31 (BGC) HSBC
    assets:Lloyds:current           £-100 = £773.72
    liabilities:mortgage

2015-03-31 (BGC) HSBC
    assets:Lloyds:current           £-100 = £1253.72
    liabilities:mortgage

2016-03-31 (BGC) HSBC
    assets:Lloyds:current           £-100 = £1203.72
    liabilities:mortgage

2017-03-31 (BGC) HSBC
    assets:Lloyds:current           £-100 = £1093.72
    liabilities:mortgage

This will look like a full amount of those payments reduce your mortgage amount, which is not right. We want to compute the amount of mortgage interest included in those payments and "move it" our of liabilities:mortgage into, let's say expenses:house:mortgage interest to properly reduce the amount of our principal.

We can use hledger-interest for this (warning: --source and --target semantics seems a bit opposite to what one would expect as we are talking about a loan, not an investment):

$ hledger-interest -f 2014.journal --source='expenses:mortgage interest' --target=liabilities:mortgage --annual=0.02 --act liabilities:mortgage -q

2014-03-31 2% interest for £-855 over 88 days
    liabilities:mortgage                £-4.12
    expenses:mortgage interest           £4.12

2014-12-31 2% interest for £-763.24 over 275 days
    liabilities:mortgage               £-11.50
    expenses:mortgage interest          £11.50

As you can see, given that our first payment occurs on 2014-03-31, hledger-interest computed the amount of interest accrued on our principal of £855 over 88 days that passed since mortgage was taken and increased amount of mortgage by the amount of interest, which would lead to a proper reduction of the principal amount once our payment of £100 lands in liabilities:mortgage.

Now we can save these transactions into a journal file which could be included into the appropriate yearly file.

Automation

There is a bit of Catch-22 here, though - if generated file is included into your yearly journal, how can you feed yearly journal into hledger-interest in order to generate the file that is included into yearly journal?

Additionally, interest transactions will modify balance of the mortgage account. What would happen when we run hledger-interest second time - would it not be confused by its own transactions?

Fortunately, we can temporarily create a completely empty mortgage interest payments file so that yearly journal will not have any broken includes, run hledger-interest, and put generated data into the file. And in the future, we can use hledger print to ignore mortgage interest payment transactions as we feed journal into hledger-interest.

All of this could be encoded as a simple script and a rule in export.hs, which you can see in 08-mortgage or diffs/07-to-08.diff.

Next steps

Remortgage