Solved

Sort Term Loan APR Calculator

Posted on 2011-09-21
13
920 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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
 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

815 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

12 Experts available now in Live!

Get 1:1 Help Now