#!/usr/local/bin/perl $args = $ENV{'QUERY_STRING'}; print "Content-type: text/html\n\n"; if (length($args) < 3) { print <Future Value/Annuity Calculation

Future Value/Annuity Calculation

Since the mortgage calcuator is so popular, I put together a form that does another calculation I find important, finding out how much to put away tax deferred to get a certain amount of money in the future, and how much you could expect to draw out of that money.


Beginning Balance of Account
Monthly contribution
Years until retirement
Estimated annual yield (%)
Estimated annual inflation (%)
Estimated annual contribution increase(%)
Desired future monthly withdrawal amount (current dollars)
FullForm } else { print "Future Estimations\n"; print "

Future Estimations

\n"; # Let's do the calculations! @va = split("&",$args); for ($i=0; $i<7; $i++) { @va[$i] = substr(@va[$i],5); } ($abal,$pymt,$time,$intr,$infl,$raiz,$wdrw) = @va; print "

Inputs

\n"; print "
Beginning Balance of Account \$ $abal\n"; print "
Initial monthly contribution \$ $pymt\n"; print "
Time until retirement $time years\n"; print "
Estimated annual yield $intr % \n"; print "
Estimated annual inflation $infl % \n"; print "
Estimated annual contribution increase $raiz % \n"; print "
Desired monthly withdrawal \$ $wdrw (current dollars)\n"; print "

\n"; $intr = $intr/1200; $raiz = $raiz/100; $infl = $infl/100; $adj = 1; print "\n"; print "
YearMonthly
Contrib
Actual
Balance"; print "
Current Dollar
Balance\n"; for ($i=0; $i<$time; $i++) { for ($j=0; $j<12; $j++) { $abal = $abal * (1 + $intr) + $pymt; } $pymt = $pymt * (1 + $raiz); $adj = $adj/(1 + $infl); $pbal = $abal * $adj; printf("
%2d \$ %9.2f \$ %11.2f \$ %11.2f\n", $i+1,$pymt,$abal,$pbal); } $awdr = $wdrw/$adj; print "

At this time:

\n"; printf("
  • Your last monthly contribution was : \$ %9.2f\n",$pymt); printf("
  • Your current required withdrawal is : \$ %9.2f\n",$awdr); print "

    Let's start taking money out and see how long it lasts

    \n"; if ($intr > 6/1200) { print "
  • Lets say you will NOT be able to maintain annual interest of"; print "more than 6% once you start taking out money\n"; print "
  • I am taking your yield down to 6.0%\n"; $intr = 6/1200; } print "\n"; $obal = $abal; print "
    YearBalanceAnnual
    Withdrawal\n"; while($abal > 0) { $yr++; $annw = 0; for ($j=0; $j<12; $j++) { if ($abal * (1 + $intr) > $awdr) { $abal = $abal * (1 + $intr) - $awdr; $annw = $annw + $awdr; } else { $annw = $annw + $abal; $abal = 0; $j = 12; } } printf("
    %2d \$ %9.2f \$ %9.2f\n", $yr, $abal, $annw); $awdr = $awdr * (1 + $infl); if ($abal > ($obal * (1 + $infl))) { print "

    Congratulations! You are set for life!

    \n"; print "Your balance is earning more than you are taking out\n"; $abal = 0; } $obal = $abal } print "\n"; }