#!/usr/local/bin/perl print "Content-type: text/html\n\n"; print "APR/Front End Cost Calculator\n"; print "\n"; $args = $ENV{'QUERY_STRING'}; $args =~ s/\+/ /g; $args =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; if (length($args) < 2) { print <APR Calculator
Enter the Loan Amount:
The quoted interest rate(%) :
Points (%) :
Other Closing Costs to include
Length of Loan (Years):

EmptyForm } else { @f = split("&",$args); for ($i=0; $i<=$#f; $i++) { $av = @f[$i]; if ($av =~ /^amt/) { $amt = substr($av,4); } if ($av =~ /^int/) { $int = substr($av,4); } if ($av =~ /^clc/) { $clc = substr($av,4); } if ($av =~ /^pts/) { $pts = substr($av,4); } if ($av =~ /^trm/) { $trm = substr($av,4); } } print "

APR Calculator Results

"; print "
"; print ""; printf("\n", $amt,$int,$trm); $mi = $int/1200; $tt = $trm * 12; $m2 = $apr/1200; $temp = (1.0 / (1 + $mi) ** $tt); $temp2 = (1.0 / (1 + $m2) ** $tt); if ($temp < 1) { $paymt = $amt * $mi / (1 - $temp); } else { $paymt = $amt / $trm; } printf("\n",$paymt); printf("\n",$amt); $pta = $amt * $pts / 100; $costs = $pta + $clc; printf("",$pts,$pta); printf("\n",$clc); printf("\n",$costs); $eamt = $amt + $costs; printf("\n",$eamt); $epaymt = $eamt * $mi / (1 - $temp); printf("\n",$epaymt); $m1 = $mi; $m2 = 2 * $mi; for ($j=0; $j<25; $j++) { $mnew = ($m1 + $m2)/2; $temp = (1.0 / (1 + $mnew) ** $tt); $epaymt2 = $amt * $mnew / (1 - $temp); if ($epaymt2 < $epaymt) { $m1 = $mnew; } else { $m2 = $mnew; } #printf("
  • %12.7f %12.7f\n",$m1,$m2); } $apr = ($m1 + $m2)*600; printf("
  • \$ %12.2f Fixed Loan at %6.3f %% for %2d Years
    Principal & Interest Monthly Payment :\$ %9.2f
    Loan Amount before closing costs:\$ %12.2f
    Points at %6.3f %%\$ %7.2f
    Other Costs\$ %7.2f
    Total up-front costs:\$ %12.2f
    So the effective amount of your loan is:\$ %12.2f
    The Monthly Payment for this amount would be:\$%9.2f
    The APR is therefore %6.4f %%
    \n",$apr); } print<