Wednesday, June 17, 2009

Here a geometric series there a geometric series

Over the past two weeks I have been running into geometric series everywhere. Geometric series are simple little equations that have the form of:

$\sum_{i=0}^{n} ak^i$

There is wiki that goes into the basics of geometric sums and their basic identies on Wikipedia: http://en.wikipedia.org/wiki/Geometric_series. For now I only present to you one of the places I have run into this little bad boy, and that is in the calculation of amortization. Every time I go through a application that does this I wondered where the math came from, I finally decided to work it out for my self.

Lets start with the knowns, r is the yearly APR, t is the number of times the APR is compounded in a year, n is the number of years, P is the principle on the loan, and D is your down payment. The only variable we are looking for X is your monthly payments. At the end of the loan term or n*t payments we would like there to be no balance in the account.

$y(0) = P - D$

Each subsequent payment takes interest from the previous period, and deducts your payment:

$y(1) = (1+r/t)y(0) - X$
$y(2) = (1+r/t)y(1) - X$
$y(nt) = (1+r/t)y(nt-1) - X$

Expanding the recursive relationship manually reveals a equation that can have Horner's Rule applied to reduce it to a more manageable form:

\begin{align*} y(nt) &= -X + (1+r/t)(-X + (1+r/t)(...\ +\\ &+ (1+r/t)(P-D)) \end{align*}

Transposing by Horner's Rule and collapsing the subsequent series into a Geometric Series:

$y(nt) = (P-D)(1+r/t)^{nt}-\sum_{i=0}^{nt-1} X (1+r/t)^i$

$y(nt) = (P-D)(1+r/t)^{nt}-X\frac{(1+r/t)^{nt}-1}{r/t}$

Recalling that at the end of the term we desire no net balance, solving for X and simplifying:

$y(nt) = 0$
$(P-D)(1+r/t)^{nt}=X\frac{(1+r/t)^{nt}-1}{r/t}$
$X=\frac{r/t(P-D)(1+r/t)^{nt}}{(1+r/t)^{nt}-1}$

Now I have the magic amortization formula in my back pocket in case I ever need it again. You can also quickly calculate your total payments Xnt or the amount of interest you paid Xnt - (P - D). The two other areas I have had the Geometric Series show up was calculating the probability of winning at a game of dice, and a 401k what if Excel sheet I made. The Dice game is really interesting because it deals with an unbounded Geometric Series.

UPDATE: A simplification of the formula above is possible:

$X=\frac{r/t(P-D)}{1-(1+r/t)^{-nt}}$

If you know how much you can pay each month X and are looking for how much of a mortgage you can afford you can resolve the equation above for P-D

$P-D=\frac{X(1-(1+r/t)^{-nt})}{r/t}$

Also note that there is a linear relationship between the amount you can pay and the amount of a mortgage you can afford.

$\frac{\partial}{\partial X}(P-D)=\frac{1-(1+r/t)^{-nt}}{r/t}$

UPDATE: Homer's Rule replaced with Horner's Rule