Solved

APR calculation help

Posted on 2009-03-28
10
276 Views
Last Modified: 2012-05-06
Hi, I want to calculate APR based on the inputs C, E, R and N.
Here is the math to solve:
http://www.efunda.com/formulae/finance/apr_calculator.cfm

I want to write in my php to calculate the APR.  But, I don't know how to solve this equation.
If not php, atleaset explain in whatever language you know, i can convert it to php.

Any help is appreciated.
Thanks.
0
Comment
Question by:CWS (haripriya)
[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
  • Learn & ask questions
  • 4
  • 4
10 Comments
 
LVL 18

Expert Comment

by:WaterStreet
ID: 24011326
Use the following formula

P = (C+E)r((1+r)^N)/((1+r)^N)-1)

The "^" symbol is whatever you programming language uses for raising to a power
0
 
LVL 16

Author Comment

by:CWS (haripriya)
ID: 24011509
Hi,
Thanks for the quick reply. P is Monthly payment. I want to calculate the APR, for which they have given a formula which should be solved using Newton Raphsons iterative method, that is where  i am stuck.
0
 
LVL 18

Expert Comment

by:WaterStreet
ID: 24011569
I can't apply the Newton Raphsons iterative method.

Maybe someone else here can help.  I'll stay subscribed.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 16

Author Comment

by:CWS (haripriya)
ID: 24011643
ok.
0
 
LVL 16

Author Comment

by:CWS (haripriya)
ID: 24012688
I solved my problem.
This is the equation I used for Newton - Raphson method.

while ((apr_next>apr+my_range_top)||(apr_next<apr)) {
apr=apr_next;
apr_next=P/loanamount*(Math.pow(1+parseFloat(apr),term)-1)/(Math.pow(1+parseFloat(apr),term));
}


This is not my code. I copied from a website.
Will close the question now.
1
 
LVL 16

Accepted Solution

by:
CWS (haripriya) earned 0 total points
ID: 24013364
This the Javascript solution that worked for me. For you to work you should use your form variables in the function.
<script language="javascript">
	function recalcapr(loantype, loanid)
	{
		if (document.forms.form1.aprtype.value=='Automatic')
		{
			if (document.forms.form1['intonly'+loanid].value=='1') var io=true;
			else var io=false;
			if (loantype=='c')
			{
				var rate=document.forms.form1['loan'+loanid+'conforming'].value;
				document.forms.form1['loan'+loanid+loantype+'apr'].value=calc_apr(document.forms.form1.othercost_con.value, rate, document.forms.form1['loan'+loanid+'term'].value, io, document.forms.form1.loanamt_con.value);
				
			}
			else
			{
				var rate=document.forms.form1['loan'+loanid+'jumbo'].value;
				document.forms.form1['loan'+loanid+loantype+'apr'].value=calc_apr(document.forms.form1.othercost_jum.value, rate, document.forms.form1['loan'+loanid+'term'].value, io, document.forms.form1.loanamt_jum.value);
			}	
		} 
	}
	
	function calc_apr(extracosts, rate,term, io,loanamount){ 
		var apr=0; 
		var total=parseFloat(loanamount)+parseFloat(extracosts);
		var P=calc_payment(total, rate, term, io); 
		rate=rate/1200;
		//alert (P);
		var apr_next=rate; 
		var my_range_top=.00000005; 
		var message='';
		var i=0;
		//Newton-Raphson method
		while ((apr_next>apr+my_range_top)||(apr_next<apr)) { 
			apr=apr_next; 
			apr_next=P/loanamount*(Math.pow(1+parseFloat(apr),term)-1)/(Math.pow(1+parseFloat(apr),term));
			} 
		return (apr*1200).toFixed(3); 
	} 
 
	function calc_apr_payment(costs, rate, term, io){
		var apr_payment=calc_payment(costs, rate, term);
		return apr_payment;
	}
 
	function calc_payment(amount, rate, term, io){
		r=rate/100/12;
		r1=r+1;
		t1=Math.pow(r1,term);
		payment=t1/(t1-1)*r*amount;
		return payment;
	}
 
</script>

Open in new window

0
 
LVL 18

Expert Comment

by:WaterStreet
ID: 24013431
Okay.  Thanks

We're just waiting for the Community Support Moderator to close the question with points refunded and your posting 24012688 as the accepted solution.
0
 
LVL 18

Expert Comment

by:WaterStreet
ID: 24014566
fine with me.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

705 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