4

Mortgage formula I'm using:

$$M = P \left(i + \frac{i}{(1+i)^n-1}\right)$$

where $M =$ payment amount, $P =$ principle balance, $i =$ term interest rate, and $n =$ number of terms.

But now I'm trying to solve for $n$ and get stuck trying to fix the exponent. I think it has to do with logarithms and I guess I slept through those classes. The farthest I can get is:

$$(1+i)^n = \frac{i}{\frac{M}{P}-1}+1$$

Phil Tune
  • 163
  • 5
  • Thanks for the help. I'm writing this function in Javascript for a handy extra payment calculator to see how fast I can pay down my student loans. (I know I could just run a loop that returns when the $\text{bal} < 0$, but Math is much more fun. – Phil Tune May 02 '14 at 15:20
  • This is a great question. There are very few resources out there on the formula for actually deriving the number of months from the formula when the payment is a certain amount. I'm using your answer to write a calculator for my own mortgage – zavtra May 29 '19 at 17:33

2 Answers2

2

If you take the natural logarithm (ln) of both sides, you get: $$n \ln (1+i) = \ln \left( \frac{i}{ \frac{M}{P}-1} + 1 \right) $$

This follows from the law $\ln(a^b) = b \ln(a)$. Then you are one step away from isolating $n$.

mweiss
  • 23,647
  • bah, that's what I figured. (I looked up a Youtube instruction.) I tried to write my new function newN = Math.log((I/((M/P)-1))+1)/Math.log(1+I); in Javascript and got a way off-base result, so I guess my math was correct but my JS is missing something. You wouldn't happen to know JS perchance? Hah. – Phil Tune May 02 '14 at 15:00
  • I think you have an error in the denominator... Shouldn't it be $M/P - i$ instead of $M/P -1$? – mweiss May 02 '14 at 15:28
  • Gentleman and a scholar you are... that fixed it! Thank you! – Phil Tune May 02 '14 at 15:35
2

@mweiss pointed me in the right direction. (Thank you!!) For anyone who runs across this, here is the completed solution:

$$n = \frac{\ln\left( \frac{i}{\frac{M}{P}-i}+1\right)}{\ln\left(1+i\right)}$$

Phil Tune
  • 163
  • 5