[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# Sort Term Loan APR Calculator

Posted on 2011-09-21
Medium Priority
1,002 Views
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
Question by:maeltar
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 7
• 6

LVL 63

Expert Comment

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>
<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>
<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>
</table>
</form>
</body>
</html>
``````
0

LVL 11

Author Comment

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;
}
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';

}
``````
0

LVL 11

Author Comment

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

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

ID: 36576145
Where do you get the 18 from ?

0

LVL 63

Expert Comment

ID: 36576725
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

Zvonko earned 2000 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

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 :

0

LVL 63

Expert Comment

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

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

LVL 63

Expert Comment

ID: 36586653
No, I cannot tell you how they get that fantasy number.
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

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

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

## Featured Post

Question has a verified solution.

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

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
###### Suggested Courses
Course of the Month12 days, 15 hours left to enroll