#!/usr/local/bin/perl print <Prepay vs. Invest

Prepayment vs. Investment -- A Scenario

Header read(STDIN,$arglist,$ENV{'CONTENT_LENGTH'}); if (length($arglist) < 3) { print< UPDATED: Now allows you to use loans where you do not deduct interest.

This form allows you to compare what would happen if you took one of two choices with some extra cash you have -- prepaying your mortgage each month, or investing it instead. This tries to take into account your tax situation and assumes you always itemize (even late into your mortgage when your interest will be lower -- I am assuming you give to charities, and pay state and local taxes too!!)

Change these fields as desired:

How much more you have to spend each month
Current monthly payment (principle & interest only)
Current Annual Loan Interest Rate
Current Loan Balance
Loan Interest Deductibility
Expected Long Term Investment Return (%)
Expected Long Term Tax Rate (%) (Federal+State)
Investment Type

EOF exit; } @iv = split("&",$arglist); for ($i=0; $i<=$#iv; $i++) { ($key,$val) = split("=",@iv[$i]); $val =~ s/%([\da-f]{1,2})/pack(C,hex($1))/eig; $val =~ s/[ ,+]//g; $aa{$key} = $val; } print ""; printf ("
Loan Balance%9.2f\n",$aa{L}); printf ("
Current Payment%9.2f\n",$aa{P}); printf ("
Additional Payment%9.2f\n",$aa{M}); printf ("
Loan Interest Rate%9.2f %%\n",$aa{R}); printf ("
Loan Interest Deductibilty%3s\n",$aa{D}); printf ("
Investment Return Rate%9.2f %%\n",$aa{Y}); printf ("
Tax Bracket %9.2f %%\n",$aa{X}); $aa{S} =~ s/\+/ /g; print "
Investment Type" . $aa{S}; print "

\n"; print ""; print ""; print "
PREPAYING"; print "INVESTING
MonthLoan Bal (P)Int Paid (P)Tax Ded (P)"; print "Loan Bal (I)Int Paid (I)Tax Ded (I)Inv Bal (I)\n"; $Pbal = $aa{L}; $Lbal = $aa{L}; # Both start with same balance $mi = $aa{R}/1200; $tf = $aa{X}/100; $my = 1 + $aa{Y}/1200; $tc = -1; while($Pbal > ($aa{P} + $aa{M}) && $m < 600) { $m++; $Pint = $Pbal * $mi; $Ptax = $Pint * $tf; $Ptint = $Ptint + $Pint; $Pbal = $Pbal + $Pint - $aa{P} - $aa{M}; $Lint = $Lbal * $mi; $Ltax = $Lint * $tf; $Ltint = $Ltint + $Lint; if ($aa{D} eq "No") { $Ltax = 0; $Ptax = 0; } $Lbal = $Lbal + $Lint - $aa{P}; $Myld = $Linv * $aa{Y}/1200; $Linv = $Linv + $Myld + $aa{M} + ($Ltax - $Ptax); if ($aa{S} =~ /After/) { $tc++; $Yyld = $Yyld + $Myld; if ($tc == 12) { $Ytax = $Yyld * $aa{X}/100; $Linv = $Linv - $Ytax; $tc = 0; $Yyld = 0; printf("
TAX------%9.2f\n",$Ytax); } } printf("
%3d%9.2f%9.2f%9.2f",$m,$Pbal,$Pint,$Ptax); printf("%9.2f%9.2f%9.2f%9.2f",$Lbal,$Lint,$Ltax,$Linv); } $lm = $m; $cLbal = $Lbal; while($Lbal > $aa{P}) { $lm++; $Lint = $Lbal * $mi; $Ltax = $Lint * $tf; $Ltint = $Ltint + $Lint; if ($aa{D} eq "No") { $Ltax = 0; $Ptax = 0; } $Lbal = $Lbal + $Lint - $aa{P}; } print "
\n"; print "

Summary

-PrepayInvest\n"; printf ("
Total Interest (%6.3f yrs)%10.2f%10.2f\n", $m/12, $Ptint,$Ltint); printf ("
Loan Payback Time (Years)%6.3f%6.3f\n",$m/12,$lm/12); print "
\n"; printf ("

Investment - Loan Balance : \$ %10.2f

\n", $Linv - $cLbal); if ($Linv - $cLbal > 0) { print "

In your case it is wiser to invest than to prepay

\n"; } else { print "

In your case it is wiser to prepay than to invest

\n"; } print <

Assumptions: This estimation assumes you will pay a fixed amount every month to either your loan prepayment or to some type of after-tax or tax deferred investment. If it is after-tax it will be more available to you, but every 12 months you will be forced to pay tax on your annual yield. This also assumes that you take the extra tax savings by NOT prepaying (prepaying lowers your deductible interest payments) and you put the tax savings into the investment as well. This also assumes that the top income tax rate will stay the same for a long time. This tax rate should also include your state income tax too if applicable. Trailer