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).
It might be this method they are using, but I can t really tell: http://www.efunda.com/math/num_rootfinding/num_rootfinding.cfm#Newton_Raphson
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.
(请注意,Im绝非数学或财务上加权)
[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 < 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) < Math.Pow(10, -5)) { break; }
}
}
double apr = ((Math.Pow((1 + d), 12)) - 1) * 100;
apr = Math.Round(apr * 100) / 100;
[/snip]