Solved

Sort Term Loan APR Calculator

Posted on 2011-09-21
13
876 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Where do you get the 18 from ?

0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
Comment Utility
"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
Comment Utility
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
Comment Utility
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
Comment Utility
Ok, fair enough, can you tell me how wonga.com achieved their 4214% apr please ?
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
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
Comment Utility
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
Comment Utility
You are welcome <|:-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to dynamically set the form action using jQuery.

763 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

6 Experts available now in Live!

Get 1:1 Help Now