#!/usr/local/bin/perl # canadian payemnts using table from Pat Pelletier 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 <How much does that loan REALLY Cost? This formula and idea was sent to me by Russ Glines at Century Oak Mortgage. You enter the interest rate of your loan, the quoted APR and the loan amount. It figures the rest.

I have written a NEW VERSION that goes the other way; you give the upfront costs and it finds the APR.


Enter the Loan Amount:
The quoted interest rate(%) :
The quoted APR (%) :
Length of Loan (Years):

EmptyForm } else { print "
"; @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 =~ /^apr/) { $apr = substr($av,4); } if ($av =~ /^trm/) { $trm = substr($av,4); } } printf("

\$ %12.2f Loan
at %6.3f %% for %2d Years

\n", $amt,$int,$trm); if ($apr < $int) { print "

Hey, the APR of $apr CANNOT be LOWER than the rate of $int !

"; print "

You either entered something wrong or have a crooked lender

"; exit; } $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("

Principal & Interest Monthly Payment : \$ %9.2f

\n",$paymt); $amt2 = $paymt * (1 - $temp2) / $m2; printf("

But at %6.3f %% that means a loan of : \$ %12.2f

\n", $apr,$amt2); printf("

So your upfront costs are: \$ %12.2f

\n",$amt-$amt2); } print< back to Mortgage Home Page
back to Mortgage Links Page

Hugh Chou TailEnd