## F# Mortgage Amortization

Simple Problemo:

What's my monthly payment for a $200,000 fixed rate 30-year mortgage at 6.00%?

let mortgage = 200000.0

let n = 360

let i = 0.06

let ones = List.init n (fun one -> 1.0)

let pv0 = presentValue ones (i/12.0)

let levelPayment = mortgage / pv0

That's all there is to it. We first set up a mortgage of $200,000, the number of periods (months) of 360 and the interest rate of 6.00%. Next, we create a vector of $1.00 for n (360) periods.

The List function

List.init n (fun one -> 1.0)

creates a List with n members and a value equal to the result of some initializer function. In my case, I just want a series of ones.

The next line

let pv0 = presentValue ones (i/12.0)

figures out the present value of my List of ones at the interest rate of i/12.0, which is the yearly interest rate converted into a monthly interest rate. My present value function is in my earlier post: F# Net Present Value; List.Fold, Head,Tail Recursion.

Why do this?

We rely of the fact that the present value of the payment stream must equal the mortgage amount.

What I want to know here is if I paid $1.00/month for 360 months, what would be it's present value. In this case the value is $167.63. Turning this around, if I had a mortgage of $167.63, my monthly payment would be $1.00. Similarly, if my mortgage was twice $$167.63, my monthly payment would be $2.00.

For a mortgage of $200,000, my payment is just equal to $200,000 divided by 167.63:

let levelPayment = mortgage / pv0

which equals $1193.14

If you want to prove this, just write two more lines:

let payments = List.init n (fun one -> levelPayment)

let pv2 = presentValue payments (i/12.0)

The first line sets up a stream of 360 payments, using our calculated level payment; the second line just takes the present value of the stream. The result (pv2) should equal the mortgage amount of $200,000.

Print | posted on Sunday, July 12, 2009 9:26 AM |