#! /bin/sh # # On the command line: a date (yyyymmdd) and a balance (in pennies), an # interest rate, and a payment amount (in pennies), in that order. Note # that the interest rate is the half-yearly rate, which is half what's # usually quoted. The payment amount is per payment, which is done twice # a month. # # Output: a series of lines, # # jdate yyyymmdd balance # # starting with the supplied date and balance, printing on the 1st and 15th # of each month, stopping with the last line whose balance is positive. # case $# in 4) ;; *) echo Usage: $0 date balance rate payment 1>&2 exit 1 ;; esac edate=`ndate -eo $1` ddate=`ndate -ei $edate` balance=$2 rate=$3 payment=$4 while case $balance in -*) false;; *) :;; esac do echo $edate $ddate $balance case $ddate in *0?|*1[01234]) nxddate=${ddate%??}15 ;; *) nxddate=`ndate $((${ddate%??}+1))01` ;; esac nxedate=`ndate -eo $nxddate` ndays=$(($nxedate - $edate)) case `ndate ${ddate%????}0229` in *0229) compden=183 ;; *0301) compden=182.5 ;; esac interest=`interest $rate $compden $ndays $balance` balance=$(($balance + $interest - $payment)) ddate=$nxddate edate=$nxedate done