Note that there are some explanatory texts on larger screens.

plurals
  1. POCalculating annual percentage rate (need some help with inherited code)
    text
    copied!<p>I'm making an application that gives clients and approximate loan offer (they are later calculated by other back-office systems). I have received some code from the financial firm that we are making the calculator for. My problem is that I do not understand the part of the code that calculates the annual percentage rate (including startup and monthly fees). </p> <p>It might be this method they are using, but I can't really tell: <a href="http://www.efunda.com/math/num_rootfinding/num_rootfinding.cfm#Newton_Raphson" rel="nofollow noreferrer">http://www.efunda.com/math/num_rootfinding/num_rootfinding.cfm#Newton_Raphson</a></p> <p>The code works correctly, but I really hate building an application on code that I don't fully understand and/or trust. The ultimate reply would be source-code which does the same thing, but with comments and understandable variable names (I'm not really excepting that :-) All ideas are welcome - maybe someone has a link to an article that explains it.</p> <p>(please note that I'm by no means a math or financial wiz)</p> <pre><code>[snip] int n = numberOfPayments; double a = (amount / (monthlyPayment * Math.Pow(n, 2)) - (monthlyPayment / amount)); double d = 0; if (a == 0) { d = 0; } else { for (int qq = 0; qq &lt; 20; qq++) { double b = amount + (monthlyPayment / a) * (1 - (Math.Pow((1 + a), -n))); double c = amount + (monthlyPayment / a) * ((n * (Math.Pow((1 + a), (-n - 1)))) - ((1 - (Math.Pow((1 + a), -n))) / a)); d = a - (b / c); double aa = a; double dd = d; a = d; if (Math.Abs(aa - dd) &lt; Math.Pow(10, -5)) { break; } } } double apr = ((Math.Pow((1 + d), 12)) - 1) * 100; apr = Math.Round(apr * 100) / 100; [/snip] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload