Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!bionet!agate!ucbvax!hplabs!hpda!hpcuhb!hpcilzb!bazavan From: bazavan@hpcilzb.HP.COM (Valentin Bazavan) Newsgroups: comp.sources.wanted Subject: Re: Rule of 78's Message-ID: <810006@hpcilzb.HP.COM> Date: 21 Aug 89 14:18:59 GMT References: <2368@wyse.wyse.com> Organization: HP Design Tech Center - Santa Clara, CA Lines: 83 Here is an awk script which prints an amortization table by the "Rule of 78." Valentin Bazavan -----------------------------Cut here----------------------------------------- # File name: r78.awk # Contents: awk program to print a "Rule of 78" amortization table # Author: Valentin Bazavan # Usage: # awk -f r78.awk [outfile] # # Note: requires the new AT&T awk or MKS awk # # When using the "rule of 78," the total interest (T) to be paid on a loan # scheduled to be amortized in N payments is artificially divided in # P = N / 2 * (N + 1) parts. (The number of parts for a 12-installment # loan is P = 12 / 2 * (12 + 1) = 78--hence the name of the rule.) # You pay N / P * T interest with the 1st payment, (N - 1) / P * T with # the 2nd, (N - 2) / P * T with the 3rd, and so on. BEGIN { out = ARGV[1] # Get input printf "Number of Payments: " getline N printf "Total Interest: " getline TotInt printf "Monthly Payment: " getline Pmt # Coerce to numeric values N = N + 0 TotInt = TotInt + 0.0 Pmt = Pmt + 0.0 if (N <= 0 || TotInt <= 0.0 || Pmt <= 0.0) { printf "Incorrect input data!\n" exit 1 } # Print header if (out) { printf("\n Amortization Table - rule of 78s\n\n") > out printf("%-9s %-26s %s\n", "Pmt.#", "Monthly Payment", "To Date") >> out printf("%-6s %-23s %s\n\n", " ", "interest principal", "interest principal") >> out } else { printf("\n Amortization Table - rule of 78s\n\n") printf("%-9s %-26s %s\n", "Pmt.#", "Monthly Payment", "To Date") printf("%-6s %-23s %s\n\n", " ", "interest principal", "interest principal") } r78part = N / 2 * (N + 1) # no. of R78 parts in N payments onepart = 1.0 / r78part * TotInt # interest per R78 part cumint = 0.0 # cumulated interest cumpr = 0.0 # cumulated principal # Print table for (i = 0; i < N; i++) { interest = onepart * (N - i) principal = Pmt - interest cumpr += principal cumint += interest if (out) printf("%4d %10.2f %11.2f %11.2f %11.2f\n", i + 1, interest, principal, cumint, cumpr) >> out else printf("%4d %10.2f %11.2f %11.2f %11.2f\n", i + 1, interest, principal, cumint, cumpr) } if (out) printf "\n" >> out else printf "\n" exit 0 }