Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating APR using Reg Z Appendix J

OK. I'm brand new to this site so "Hello All"! Well I've been wrestling with a difficult problem for the last week and I would appreciate any help you can give me.

I know there are many formulas out there to calculate APR but I've tested many formulas and they do not handle Odd-Days properly for closed-end (consumer loans). The government has attempted to give us mere mortals some help with this by publishing an Appendix J to their truth-in-lending act. It can be found here: https://www.fdic.gov/regulations/laws/rules/6500-3550.html

If you're brave (!!), you can see the formulas they provide which will solve for the APR, including the Odd-Days of the loan. Odd-Days are the days at the beginning of the loan that isn't really covered by a regular period payment but interest is still being charged. For example, you take a loan for $1,000.00 on 01/20/2012 and your first payment is 03/01/2012. You have 10 odd-days from 01/20/2012 to 01/30/2012. All months are 30 days for their calcs.

What I'm hoping for is someone with a significant background in Calculus who can interpret the the formulas you'll find about half way down Appendix J. And interpret the Actuarial method they're using to solve these formulas. I understand the iterative process. I first tried to solve this using the Newton-Raphson method but my formula for the APR did not account for the Odd-days. It worked great in the unlikely trivial case where there are no odd days, but struggled with odd-days.

I know that reading this document is very difficult! I've made some headway but there are certain things I just can't figure out how they're doing. They seem to introduce a few things as if by magic.

Anyways thanks ahead of time for helping! :)

like image 295
Dave Nesbitt Avatar asked Feb 17 '12 13:02

Dave Nesbitt


2 Answers

Alright, you weren't kidding about the document being a bit hard to read. The solution is actually not that bad though, depending on implementation. I failed repeatedly trying to use their various simplified forumulae and eventually got it using the general formula up top(8). Technically this is a simplification. The actual general formula would take arrays of length period for the other arguments and use their indexes in the loop. You use this method to get A' and A'' for the iteration step. Odd days are handled by (1.0 + fractions*rate), which appears as 1 + f i in the document. Rate is the rate per period, not overall apr.

public double generalEquation(int period, double payment, double initialPeriods, double fractions, double rate)
{
    double retval = 0;
    for (int x = 0; x < period; x++)
        retval += payment / ((1.0 + fractions*rate)*Math.pow(1+rate,initialPeriods + x));
    return retval;
}

Iteration behaves just as the document says in its example(9).

/**
 * 
 * @param amount The initial amount A
 * @param payment The periodic payment P
 * @param payments The total number of payments n
 * @param ppy The number of payment periods per year 
 * @param APRGuess The guess to start estimating from, 10% is 0.1, not 0.001
 * @param partial Odd days, as a fraction of a pay period.  10 days of a month is 0.33333...
 * @param full Full pay periods before the first payment.  Usually 1.
 * @return The calculated APR
 */
public double findAPRGEQ(double amount, double payment, int payments, double ppy, double APRGuess, double partial, double full)    
{
    double result = APRGuess;
    double tempguess = APRGuess;       

    do
    {
        result = tempguess;
        //Step 1
        double i = tempguess/(100*ppy);
        double A1 = generalEquation(payments, payment, full, partial, i);
        //Step 2
        double i2 = (tempguess + 0.1)/(100*ppy);
        double A2 = generalEquation(payments, payment, full, partial, i2);
        //Step 3
        tempguess = tempguess + 0.1*(amount - A1)/(A2 - A1);
        System.out.println(tempguess);
    } while (Math.abs(result*10000 - tempguess*10000) > 1);
    return result; 
}

Note that as a general rule it is BAD to use double for monetary calculations as I have done here, but I'm writing a SO example, not production code. Also, it's java instead of .net, but it should help you with the algorithm.

like image 195
Thomas Avatar answered Oct 06 '22 10:10

Thomas


Tho this is an old thread, I'd like to help others avoid wasting time on this - translating the code to PHP (or even javascript), gives wildly inaccurate results, causing me to wonder if it really worked in Java -

<?php
function generalEquation($period, $payment, $initialPeriods, $fractions, $rate){
    $retval = 0;
    for ($x = 0; $x < $period; $x++)
        $retval += $payment / ((1.0 + $fractions*$rate)*pow(1+$rate,$initialPeriods + $x));
    return $retval;
}

/**
 * 
 * @param amount The initial amount A
 * @param payment The periodic payment P
 * @param payments The total number of payments n
 * @param ppy The number of payment periods per year 
 * @param APRGuess The guess to start estimating from, 10% is 0.1, not 0.001
 * @param partial Odd days, as a fraction of a pay period.  10 days of a month is 0.33333...
 * @param full Full pay periods before the first payment.  Usually 1.
 * @return The calculated APR
 */
function findAPR($amount, $payment, $payments, $ppy, $APRGuess, $partial, $full)    
{
    $result = $APRGuess;
    $tempguess = $APRGuess;       

    do
    {
        $result = $tempguess;
        //Step 1
        $i = $tempguess/(100*$ppy);
        $A1 = generalEquation($payments, $payment, $full, $partial, $i);
        //Step 2
        $i2 = ($tempguess + 0.1)/(100*$ppy);
        $A2 = generalEquation($payments, $payment, $full, $partial, $i2);
        //Step 3
        $tempguess = $tempguess + 0.1*($amount - $A1)/($A2 - $A1);
    } while (abs($result*10000 - $tempguess*10000) > 1);
    return $result; 
}
// these figures should calculate to 12.5 apr (see below)..
$apr = findAPR(10000,389.84,(30*389.84),12,.11,0,1);
echo "APR: $apr" . "%";
?>

APR: 12.5000% Total Financial Charges: $1,695.32 Amount Financed: $10,000.00 Total Payments: $11,695.32 Total Loan: $10,000.00 Monthly Payment: $389.84 Total Interest: $1,695.32

like image 33
CompuSolver Avatar answered Oct 06 '22 11:10

CompuSolver