Financial Functions in financial.mac

Maxima by Example, Ch. 15, Financial Mathematics

Edwin L. (Ted) Woollett


This html file (financial.html), financial.mac, financial.wxm, and financial_brief.wxm are available for download at Ted's CSULB webpage: http://web.csulb.edu/~woollett/


A.     Rounding Floating Point Numbers and Printing All Matrix Rows
  1. rnddp  (expr, dp)    if expr is a floating point number (a float), round expr to dp decimal places (dp stands for decimal places)
  2. rnd_list_dp  (alist,   dp)     round floats in list alist to dp decimal places
  3. rnd_matrix_dp  (M,   dp)    round floats in matrix M to dp decimal places
  4. print_matrix   (M)     print all rows of matrix M

B.     Time Value of Money Functions
  1. pv  (i,   FV,   n)    present value of a single payment FV made n periods in the future with interest rate i
  2. fv  (i,   PV,   n)     future value of a single payment PV made n periods in the past with interest rate i
  3. npv   (i,   cfL)    net present value (t = 0) of a stream of signed cash flows included in the list cfL. List element cfL[1] is the cash flow at t=0. The number of cash flows is the length of the list cfL, and the assumed interest rate is i
  4. irr   (cfL,   IO)    calculate the internal rate of return (IRR) based on a cash flow list cfL of signed values, with the first element of the list representing t = 0, and also based on a possibly separate accounting of an initial investment (IO) made at t = 0.
  5. benefit_cost   (rate,   CFin,  CFout)    benefit/cost ratio, based of list CFin (list of cash flows in) and CFout (list of cash flows out), with both lists having the same length, and mathematically the same as
    npv(rate, CFin) divided by npv(rate,CFout)
  6. days360   (year1,   month1,  day1,  year2,   month2,  day2 )    A crude calculation of the number of days between two dates, assuming each year contains 360 days and each month contains 30 days.
       days360 (2007,  3,  25,  2008,  12,  16)   ==>   621
  7. plot_CF   (cfL,   lineWidth)    makes a histogram with blue vectors on the top side for positive entries, and red vectors on the bottom side for negative vectors using draw2d, which is loaded when you load financial.mac.
    cfL is a either a list like [100, -50, 200, 300, -100] which assumes the cash flows occur only at the beginning or end of compounding periods, or like [ [0.5,100],[1,-50],[2,200],[2.5,300],[4,-100] ] in which each sublist has the form [time, cash_flow]. lineWidth is a positive number, say 5 or 6, which controls the line width.

C.     Ordinary Annuity Functions
  1. FV_stream   (i,  A,  n)    Future Value (value at the time of the last payment) of an ordinary annuity immediate stream of constant periodic payments A made at the end of n equal compounding periods, assuming interest rate per period i
  2. annuity_fv   (i,  FV,  n)    Returns the ordinary annuity (the constant and periodic payment) paid at the end of each of n compounding periods, given the interest rate i per period, and given the required future value FV (the value at the time of the last payment)
  3. savingA   (i,   Amount,  n)   constant periodic deposits in a savings account over n periods to achieve a savings goal of Amount, given the periodic interest rate i. The result is a Maxima matrix which gives a decent table display, with four columns (period, accum. balance, interest made per period, and constant deposit amount.
    savingA assumes the first savings deposit occurs at k = 1, and the last occurs at k = n to reach the savings goal = Amount
  4. savingB   (i,   Amount,  n)   similar to savingA, except that the first savings deposit occurs at t = 0 and immediately starts accruing interest, the last deposit occurs at time k = n, resulting in a lower constant periodic deposit, n+1 deposits, and a final balance larger than via the scenario of savingA.
  5. PV_stream   (i,  A, n)    Present Value (t = 0) of an ordinary annuity immediate stream of n constant payments A each made at the end of a compounding period, assuming the interest rate per period i. The first payment is made at time k = 1, and the last at time k = n.
  6. annuity_pv   (i,  PV,  n)    Returns the annuity (the constant periodic payment at the end of each of n compounding periods) based on the present value (PV) of the stream of deposits in an ordinary annuity, and the interest rate i per compounding period.
  7. amortization   (i, PV, n)   Constant payment schedule for paying off a loan;   this function returns a matrix table (schedule) showing how each successive constant payment of an ordinary annuity divides into a payment of interest on the principal balance, and a portion (the amortization) which reduces the principal balance itself.

D.     Arithmetic Increasing Annuity Functions
We assume an "increasing annuity immediate" in which the increasing payments occur at the end of each compounding period, and in which Q is the constant payment increment.

In more detail: the first payment = R, the second payment = R + Q, the third payment = R + 2*Q, etc, and the nth and final payment = R + (n-1)*Q.



  1. PV_arith   (i,  R,  Q,  n)    a "brute force" calculation of the present value (t =0) of an arithmetic increasing stream of n payments (as described above), assuming interest rate per period i. This function explicitly calls the Maxima sum function, rather than using the more efficient summed expression available and used in PV_AI_stream.
  2. PV_AI_stream   (i, R, Q, n)    PV_AI_stream should return the same present value as PV_arith, but uses a finite sum expression instead of an explicit sum, and is thus more efficient.
  3. AI_annuity_pv   (i,  PV,  Q,  n)    returns the first payment (R) made at the end of the first compounding period for an arithmetic-increasing payment annuity, given the interest rate per period i, the constant payment increment Q, and the number of payments n.
  4. amortization_arith   (i,  PV,  Q,  n)   returns a matrix display (table) of the amortization schedule for an arithmetic increasing annuity immediate given the interest rate per payment period i, a (t=0) present value PV, a constant payment increment Q, and n payments.

E.     Growing ("Geometric Increasing") Annuity Functions
These formulas deal with a stream of payments made at the ends of n equal periods, assuming an interest rate i, first payment R, and each succeeding payment is (1+g) times larger than the previous payment. We call g the payment growth rate.

  1. PV_geom   (i,  g,  R,  n)    calculates the present value (t = 0) of a stream of future payments made at the ends of n equal periods, assuming an interest rate i, first payment R, and each succeeding payment is (1+g) times larger than the previous payment. This function explicitly calls the Maxima sum function and is not as efficient as PV_GI_stream.
  2. PV_GI_stream   (i, g, R,  n)    should return the same present value (t=0) as PV_geom, but uses the geometric series summation formula instead of an explicit call to the Maxima sum function, and is thus more efficient.
  3. GI_annuity_pv   (i,  g,  PV,  n)    returns the first payment of a geometric increasing stream of payments, given the present value PV, the periodic interest rate i, the payment growth rate g, and the number n of compounding periods.
  4. amortization_geom   (i,  g,   PV,  n)    returns a matrix table display of the amortization schedule for a geometic increasing ordinary annuity, assuming interest rate i, payment growth rate g, and a (t=0) present value PV, and n payment periods.
  5. FV_geom  (i,  g,  R,  n)    calculates the future value (value at the time of the last payment) of a growing annuity (assuming interest rate i, payment growth rate g, first payment R, and n payments) using an explicit call to the Maxima sum function, and is not as efficient as FV_GI_stream.
  6. FV_GI_stream   (i,  g,  R,  n)    should return the same future value as FV_geom, but uses the geometric series summation formula instead of an explicit call to the Maxima sum function, and is thus more efficient.
  7. GI_annuity_fv   (i,  g,  FV,  n)    returns the first payment (at k = 1) of a geometric increasing stream of payments, given the future value FV (at k = n), the interest rate i, payment growth rate g, and the number n of periodic payments.

F.     List Utilites:     Functions for examining long lists.
  1. fll   (aList)    returns a three element list containing the first element, the last element, and the length.
  2. head   (aList)    returns a three element list containing the first 3 elements of the list.
  3. tail   (aList)    returns a three element list containing the last 3 elements of the list.