P = (C+E)r((1+r)^N)/((1+r)^N)-
The "^" symbol is whatever you programming language uses for raising to a power
<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>
Title | # Comments | Views | Activity |
---|---|---|---|
Wordpress Query | 1 | 35 | |
Wordpress syntax error | 1 | 29 | |
SQL inner join confusion | 15 | 22 | |
php ssh2_scp_send | 1 | 6 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
19 Experts available now in Live!