#!/usr/local/bin/perl #******************************************************************** # # loan.pl : Script computes an amortization of a potential loan. # # G. K. Fenton 1/1997 # #******************************************************************** # # Definitions of main variables... # $price = Total Cost of Item. # $down_pmt = Down Payment which takes away from Price. # $N = Term of Loan in units of (Months). # $I = Interest Rate divided by 12 for units of Months then # divided by 100 to put into a percentage format. # $dataout = Plot file name used by GnuPlot, Default name # is 'data'. # #******************************************************************** # # $Id: loan.pl,v 1.1.1.1 1999/12/18 02:06:03 curt Exp $ # (Log is kept at end of this file) $dataout = "data"; # Process the Command Line Arguments # print @ARGV,"\n"; # print $#ARGV+1,"\n"; if ($#ARGV+1 < 8) { print "\n\n loan.pl : This Script computes an amortization of a potential loan.\n\n"; print " Usage: loan.pl [-p ] [-d ] [-t ] [-i ] [-o ]\n\n"; print "\n Example: loan -p 100000 -d 10000 -t 360 -i 7.0 \n\n"; print " Where, -p --> Price to be financed.\n"; print " -d --> Down Payment.\n"; print " -t --> Loan Term in Months.\n"; print " -i --> Annual Percentage Rate.\n"; print " -o --> Output data file name.\n\n"; exit(1); } $i = 0; foreach (@ARGV) { if ($ARGV[$i] eq "-p") { # Get the Price or Cost of Loan. $price = $ARGV[$i+1]; } if ($ARGV[$i] eq "-d") { # Get the Down Payment for Loan. $down_pmt = $ARGV[$i+1]; } if ($ARGV[$i] eq "-t") { # Get the Term of the Loan in Months. $N = $ARGV[$i+1]; } if ($ARGV[$i] eq "-i") { # Get the Interest Rate of the Loan. $I = $ARGV[$i+1]; $I = $I/12.0/100.0; # Put into Monthly percentage Units. } if ($ARGV[$i] eq "-o") { # Get the output data file name. $dataout = $ARGV[$i+1]; } $i++; } $loan_amt = $price; $tmp_var = (1.0 + $I)**$N; $payment = $loan_amt * $I * $tmp_var/($tmp_var - 1.0); open(FOUT, ">$dataout") || die "\n\n Warning: Can't open output file '$dataout' !\n\n"; $balance[0] = $loan_amt; for( $i=1 ; $i<=$N ; $i++ ) { $balance[$i] = $balance[$i-1] * (1 + $I) - $payment; $interest[$i] = $balance[$i-1] * $I; $principal[$i] = $payment - $interest[$i]; $equity[$i] = $price - $balance[$i]; print FOUT " $i, $balance[$i], $equity[$i], $interest[$i], $principal[$i]\n"; } close(FOUT); $sum_payment = 0.0; $sum_principal = 0.0; $sum_interest = 0.0; for( $i=1 ; $i<=$N ; $i++ ) { $sum_payment += $payment; $sum_principal += $principal[$i]; $sum_interest += $interest[$i]; } printf("\n Cost Amount = \$%7.2f\n", $price); printf(" Down Payment = \$%7.2f\n", $down_pmt); printf(" Loan Amount = \$%7.2f\n", $loan_amt); printf(" >>> Monthly Payment = \$%7.2f <<<\n\n", $payment); printf("------- Data over Life of Loan -------\n"); printf(" Principal Only = \$%7.2f\n", $sum_principal); printf(" Interest Only = \$%7.2f\n", $sum_interest); printf(" Total Payment = \$%7.2f\n", $sum_payment); printf("\n Created Plot File < $dataout >!\n"); printf(" Use GnuPlot to see the curves...\n\n"); exit(0); # ---------------------------------------------------------------------------- # $Log: loan.pl,v $ # Revision 1.1.1.1 1999/12/18 02:06:03 curt # Start of 0.8 branch # # Revision 1.1 1999/12/17 19:21:02 curt # Added to repository. # # Revision 2.3 1999/01/13 22:40:30 curt # Fixed a small bug in import_qif() relating to the logic of properly # reconstructing splits. # # Added a script to convert MYM files to CBB. Contributed by Brian # # # Added an Emacs "edb" interface to the contrib section. Provided by # Bob Newell # # Preserve owner, group, and permissions of CBB files # # Added a loan_recur.pl script from Michel Verdier which does the same # thing as loan.pl, but also generates recuring transactions for the # payments. # # Patch from Michel Verdier to help recur.pl better handle recurring # transfer transactions. # # Added initial support for binding an arbitrary math function to the # debit and credit fields in the main transaction editor section. This # is useful for doing things like currency conversions. You can enter # in one currency and then use a hot key to convert to your "canonical" # currency. # # Revision 2.2 1997/01/10 19:05:10 curt # Initial revision. #