#!/usr/local/bin/perl print <What prepayment does to your loan
Header $args = $ENV{'QUERY_STRING'}; $args =~ s/\+/ /g; $args =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; if (length($args) < 2) { print <How will prepaying change my loan?
This calculator takes a principal amount, interest rate, normal length of the loan and either how much total a month to pay or how long you want to pay. Then it thinks...

NEW Now also calculates for credit cards and other non amortized lines of credit that use simple compounding of interest.


Enter your loan amount: -
Your interest rate: % (1 to 100)
Amortized Length of mortgage:
Enter "0" for credit card and other non amortized lines of credit
This is value you want to set

EmptyForm } else { print "
"; @f = split("&",$args); for ($i=0; $i<=$#f; $i++) { $av = @f[$i]; $av =~ s/[ ,+]//g; if ($av =~ /^amt/) { $amt = substr($av,4); } if ($av =~ /^int/) { $int = substr($av,4); } if ($av =~ /^len/) { $len = substr($av,4); } if ($av =~ /^opt/) { $opt = substr($av,4); } if ($av =~ /^ovl/) { $ovl = substr($av,4); } if ($av =~ /^out/) { $out = substr($av,4); } } if ($opt =~ /Length/) { $opt = "LENGTH"; } else { $opt = "AMOUNT"; } $thou = $amt/1000; #$int = $ir1 + $ir2; print "(For a loan of \$ $amt at a interest rate of $int %\n"; print "for $len years)\n"; $tt = $len * 12; $i = $int / 1200; if ($tt > 0) { if ($i > 0) { $paymt = $amt * $i / (1 - ((1 + $i) ** -$tt)); } else { $paymt = $amt / $tt; } printf("

The standard payment (principal & interest) : \$ %9.2f

\n", $paymt); } else { $paymt = 0; } if ($opt eq "AMOUNT") { if ($ovl < $paymt) { print "

Sorry, you did not pay enough!

\n"; printf("

You entered \$ %9.2f, You need \$ %9.2f more

\n", $ovl, $paymt - $ovl); } else { printf("

You entered \$ %9.2f

\n", $ovl); if ($paymt > 0) { printf("

That's an extra \$ %9.2f each month

\n", $ovl - $paymt); } if ($ovl < $amt * $i && $tt == 0) { printf("

But that's less than the interest of \$ %9.2f

", $amt * $i); exit; } $eti = $paymt * $tt - $amt; if ($out =~ /Full/) { print "\n
MonthPrincipalInterestBalanceTot Int\n"; } while($amt > 0 && $m < 1200) { $ti = $ti + $amt * $i; $ci = $amt * $i; $p = $ovl - $ci; $amt = $amt * (1 + $i) - $ovl; $m++; if ($out =~ /Full/) { printf("
%3d%9.2f%9.2f%9.2f%9.2f\n", $m,$p,$ci,$amt,$ti); } } if ($out =~ /Full/) { print "
\n"; } $y = $m/12; printf("

You paid it off in %3d months (%6.3f years)

\n", $m, $y); if ($tt > 0) { printf("
  • Expected total interest : \$ %10.2f\n",$eti); } printf("
  • Your total interest : \$ %10.2f\n",$ti); if ($tt > 0) { printf("
  • Total interest saved : \$ %10.2f\n",$eti - $ti); } } } else { if ($ovl > $len && $tt > 0) { print "

    Sorry, it can't take longer than the amortization

    "; print "

    That's called defaulting on your loan!

    "; } else { $dm = $ovl * 12; $dpt_l = $paymt; $dpt_h = 10 * $paymt; $m = 0; if ($dpt_h == 0) { $dpt_h = $amt; } while($dpt_h > $dpt_l + .01) { $dpt = ($dpt_l + $dpt_h) / 2; $m = 0; $amtt = $amt; while($amtt > 0 && $m < 1200) { $amtt = $amtt * (1 + $i) - $dpt; $m++; } if ($m < $dm) { $dpt_h = $dpt; } else { $dpt_l = $dpt; } } if ($out =~ /Full/) { print "\n"; print "
    MonthPrincipalInterestBalanceTot Int\n"; $amtt = $amt; while($amtt > 0 && $j < 1200) { $ci = $amtt * $i; $p = $dpt - $ci; $amtt = $amtt * (1 + $i) - $dpt; $j++; $ti = $ti + $ci; printf("
    %2d%9.2f%9.2f%9.2f%9.2f\n", $j, $p, $ci, $amtt, $ti); } print "
    \n"; } print "

    Over $ovl Years

    \n"; printf("

    Required Monthly Payment: \$ %7.2f

    \n",$dpt); printf("

    (\$ %7.2f extra a month)

    \n",$dpt - $paymt); } } } print<