# jmtd → log → Haskell mortgage calculator

A few months ago I was trying to compare two mortgage offers, and ended up writing a small mortgage calculator to help me. Both mortgages were fixed-term for the same time period (5 years). One of the mortgages had a lower rate than the other, but much higher arrangement fees.

A broker recommended the mortgage with the higher rate but lower fee, on an affordability basis for the fixed term: over all, we would spend less money within the fixed term on that deal than the other. (I thought) this left one bit of information missing: what remaining balance would there be at the end of the term?

The mortgages I want to model are defined in terms of a monthly repayment
figure and an annual interest rate for the fixed period. I *think* interest is
usually recalculated on a daily basis, so I convert the annual rate down to a
daily rate.

Repayments only happen once a month. Months are not all the same size.
Using `mod 30`

on the 'day' approximates a monthly payment. Over 5 years,
there would be 60 months, meaning 60 repayments. (I'm ignoring leap years)

```
λ> length . filter id .take (5*365) $ [ x`mod`30==0 | x <- [1..]]
60
```

Here's what I came up with. I was a little concerned the repayment approximation was too far out so I compared the output with a more precise (but boring) spreadsheet and they agreed to within an acceptable tolerance.

The numbers that follow are all made up to illustrate the function and don't reflect my actual mortgage.

```
borrowed = 1000000 -- day 0 amount outstanding
aer = 0.89
repay = 1000
der = aer / 36
owed n | n == 0 = borrowed
| n `mod` 30 == 0 = last + interest - repay
| otherwise = last + interest
where
last = owed (n - 1)
interest = last * der
```

## Comments