That isn't code. Those are comments showing how the relatively simple equation was derived. Namely:

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

In reply to Re^3: Monthly Payment Analyzer (comments) by tye
in thread Monthly Payment Analyzer by sulfericacid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.