Solved

Sort Term Loan APR Calculator

Posted on 2011-09-21
13
902 Views
Last Modified: 2012-05-12
Hi All,
I'd like some help with putting together a short term loan apr calculator.

Most of the solutions I have found online ony work with Months/Years I need one that will work with days.

i.e.
Loan = £100
Repayment = £150
Period = 20 days
In this instance the Interest would be 50% but what would the (UK) APR be ?

Input should be Loan, Period and Int. Rate giving a result of the APR.

I would prefer PHP, but if someone has something hidden away in Javascript that would work as well..

Thanks Experts
0
Comment
Question by:maeltar
  • 7
  • 6
13 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 36572161
You did not state what APR you calculate on paper.
I do get 900% when I calculate twelve months by thirty days.
And this is my page:
<html>
<head>
<title>Zvonko &#42;</title>
<script>
function getAPR(theForm){
  var theLoan = theForm.inpLoan.value*1;
  var thePay = theForm.inpRepaiment.value*1;
  var theDays = theForm.inpDays.value*1;
  theForm.outApr.value="";
  if(theLoan&&thePay&&theDays){
    theAPR=(thePay-theLoan)/theLoan*100*360/theDays;
	theForm.outApr.value=theAPR.toFixed(2);
  }
}
</script>
</head>
<body>
<form onKeyUp="getAPR(this)">
<table>
<tr><td>Loan</td><td>
<input type="text" name="inpLoan" ></td></tr>
<tr><td>Repaiment</td><td>
<input type="text" name="inpRepaiment" ></td></tr>
<tr><td>Days</td><td>
<input type="text" name="inpDays" ></td></tr>
<tr><td>APR[%]</td><td>
<input type="text" name="outApr" readonly></td></tr>
</table>
</form>
</body>
</html>

Open in new window

0
 
LVL 11

Author Comment

by:maeltar
ID: 36572210
The APR should be in the region of 4200%

I have been using the following Javascript....

The refrence to Issac's magic is to : http://en.wikipedia.org/wiki/Newton%27s_method

setPPA(52)

function CalcRate() {
  var p = getVal(document.input.credit.value);
  var i=getVal(document.input.initial.value);
  var a=getVal(document.input.repay.value);
  var n=Math.floor(getVal(document.input.number.value));
  var f=getVal(document.input.last.value);

  //Isaac's magic ...

  var x=1.0001; var fx=0; var dx=0; var z=0;
  do {
    fx=i+a*(Math.pow(x,n+1)-x)/(x-1)+f*Math.pow(x,n)-p;
    dx=a*(n*Math.pow(x,n+1)-(n+1)*Math.pow(x,n)+1)/Math.pow(x-1,2)+n*f*Math.pow(x,n-1);
    z=fx/dx; x=x-z;
    //alert("fx="+fx+"\ndx="+dx+"\nz="+z+"\nx="+x)
    }
    while (Math.abs(z)>1e-9);
     r=100*(Math.pow(1/x,m)-1);

  document.input.credit.value=TwoDP(p);
  document.input.initial.value=TwoDP(i);
  document.input.repay.value=TwoDP(a);
  document.input.number.value=n;
  document.input.last.value=TwoDP(f);

  document.getElementById('showapr').innerHTML = "APR : " + OneDP(r) + " %";
  document.getElementById('showapr').style.visibility = 'visible';

}

Open in new window

0
 
LVL 11

Author Comment

by:maeltar
ID: 36572213
Oh, I did not write that, code.

From what I understand the setPPA() is the payment periods per annum (a guess)
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 36573014
Take paper and pencil and write down what you expect.
I do this:
The Year has 360 days and you pay interessts for 20 days and therefore you have to multiply the intersts percents by: 18
You see so far?
And then is 50% multiplied by 18: 900%
And not 4200 percent.

The 4200 percent from the calculation above is something else that you perhaps want but that I do not know how to calculate: if you calculate the interest not only for the Loan but also for the DAILY!!! interesst that you owe then it gets that high at the end of the day.
0
 
LVL 11

Author Comment

by:maeltar
ID: 36576145
Where do you get the 18 from ?

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 36576725
Read this:
http://en.wikipedia.org/wiki/Annual_percentage_rate

Read that and that write down how you want to calculate your percentages.
I can transform anything that you can calculate to JavaScript.
But JavaScript does not have the guess_what_I_nead() function, at least not yet <|;-)

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 36576999
"Where do you get the 18 from ?"

You did NOT read this: http:#36573014

The 18 is the multiplier.
If your interests was for 20 days and you assume the year has 360 days then is the factor for 20 days this:
360 / 20 :== 18

The number of days to be 360 is a German bank calculation method to assume 12 months by 30 days.

But I think you see the question far too complicated.
All APR calculators try to solve the decrease of loan amount by monthly payment and increase of interest rate because you pay same amount every month for the interest.

But in your question you do not have monthly payments.
You confuse it because you have amount of days but you still pay back at once. So the APR is simply that percentage for repayment multiplied by the factor. In your example the factor is: 18

You see the 42 in the title of my example? That number is my favorite answer :-) Enter that number into Google and see what you get: 42 is the answer to all and everything if you know the question ;-)

0
 
LVL 11

Author Comment

by:maeltar
ID: 36585961
Zvonko, yes I think you are correct in that I am seeing it as more complicated that it actually is. However I am sure it is not as easy as you show.

I got my approximation of 4200% apr from http://www.wonga.com (using that as an example).
Note, that Wonga also only allow one payment.

Using 365 as days in the year :

365/20 == 18.25

18.25 * 50% = 912.50%

I have read the wiki page a number of times and maybe I am looking at the wrong place, but :

http://en.wikipedia.org/wiki/Annual_percentage_rate#European_Union

Shows the formula using the Newton-Raphson method which I believe I need to calculate it correctly (to meet legal requirements).

So the formula that I need turning into code is :

http://upload.wikimedia.org/math/f/4/a/f4a38e606f03ce70c274fe4e4f30f26f.png
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 36586261
You do not have a Sigma over one to N payments because your payment is done once.

And for the 365 change that days number in my example from 360 to 365 and you are done.

0
 
LVL 11

Author Comment

by:maeltar
ID: 36586514
Ok, fair enough, can you tell me how wonga.com achieved their 4214% apr please ?
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 36586653
No, I cannot tell you how they get that fantasy number.
Read this page section three:
http://www.wonga.com/money/is-this-apr-expensive

Then you will understand why they confuse the customers with that fantasy number.
Legally they are bound to tell you the APR. But they cannot.
The only thing is that they calculate 360% interests per anum. That is already extra orbital. But to hide that extra orbital interests they confuse the customer with even much higher percentage number to bring you back to trust their sliders and decide on your own whether you want to pay 360% percents (one percent for every day) or you do not want.

In Germany are such business forbidden.

0
 
LVL 11

Author Comment

by:maeltar
ID: 36586772
Ahhh  now that is an excellent find :-)

But that's because the calculation required by law means that, where a loan is not taken out for a year, the interest rate must be compounded the same number of times the actual loan period would fit into a year.

So I just need to compound the rate and I will get the apr, ok, thank you very much for your time and patience helping me to understand this ...
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 36586838
You are welcome <|:-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now