p = P * r^N / [ (r^N-1) / (r-1) ]
where
r = (1+i/f)
I didn't look at your code in detail. Looking more closely now, I would say that either your concept of "interest" incorporates much more than the interest rate that would normally be quoted when getting a loan or your code is simplistic to the point of being very inaccurate.
Try running my script with some sample data and compare it to your script if you want to get a better idea of how much difference there is.
Note that my script wants the simple interest rate for the loan. This is not "APR" (Annual Percentage Rate) which takes into account how the simple interest is compounded.
So a simple 8% loan with interest compounded monthly would have an APR of 100*( (1+0.08/12)^12 - 1 )% or about 8.3%. For such a loan, you'd tell my script "8%".
Note that ^ is used for exponentiation in the math equations I've shown and you'd use ** instead if writing similar code in Perl.
A somewhat simpler equation that I've seen loan officers use makes the assumption that you'll pay about 1/2 as much interest in paying off the loan as would accrue if you made no payments. Or:
p = P * [ (1+i/f)^N + 1 ] / 2
This equation is much simpler to derive, but is only a little simpler to use than my very accurate one, so I don't use it. I'm not sure why loan officers use it, since I doubt they care whether or not they know how to derive the formula. Perhaps it is easier to use with a typical adding machine?
- tye
|