@ifplaintext
\input texinfo
@settitle finance -- Cash flow and present value
@setfilename finance.txt
@copying
This manual is for workspace assert version  0 1 2.

Copyright @copyright{} 2019 Bill Daly

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
@end copying

@titlepage
@title finance -- Cash flow and present value
@author Bill Daly

@end titlepage

@ifnottex
@node TOP
@end ifnottex

@end ifplaintext

@ifnotplaintext
@node finance
@end ifnotplaintext

@chapter finance -- Cash flow and present value
@cindex finance
@cindex present value
@cindex discounted cash flow


The finance workspace provides functions useful in understanding the
cash flow and cash requirements of an enterprise and for planning and
managing that cash flow.

@section Simple amounts

These functions work on a single cash payment. Each function expects a
right argument vector of amount, interest rate, and number of periods.

@deffn ∇ future_amt ← fin∆compoundValue arg

Calculate the future value of a single sum. All arguments are made in
a single right-argument vector of cash invested, interest rate per
period, and  number of periods.
	
Interest rates are generally quoted at an annual rate ignoring the
effects of compounding. Therefore $100 invested at 12% per annum and
compounded monthly would yield $112.68 from entering 

@verbatim
      fin∆compoundValue 100, (.12÷12) 12
112.68
@end verbatim
@end deffn

@deffn ∇ amt ← fin∆presentValue arg

Function calculates the present value of a single sum payable in n
periods. The right argument is assembled as with fin∆compoundValue. This
is the reverse of fin∆compound value:

@verbatim
      fin∆presentValue 112.68 .01 12
100
@end verbatim
@end deffn

@section Periodic payments

These functions work on a flow of cash.  For instance a mortgage
(called an annuity here) is usually a loan of a specific sum (negative
cash flow) followed by monthly payments and a fixed amount (positive
cash flow). For these function the following datum appear

@defvar pay

The periodic payment
@end defvar

@defvar i

The interest per period
@end defvar

@defvar n

The number of periods.
@end defvar

@deffn ∇ amt ← fin∆presentValueAnnuity vector of pay i n

Function calculates the present value of an annuity, that is the
amount of a loan today in exchange for a payment in each of N periods.
The right argument is a vector of the payment, interest rate, and
number of periods, viz.:

@verbatim
      fin∆presentValueAnnuity 100 .01 360
9721.83
@end verbatim

@end deffn

@deffn ∇ amt ← fin∆compoundAnnuity vector of pay i n

Function calculates the future value of an annuity. That is the amount in a
savings account after n periods of depositing the same amount. 

@verbatim
      fin∆compoundAnnuity 100 .01 360
352991.38
@end verbatim
@end deffn

@deffn ∇ amt← i fin∆netPresentValue vector_of_cash_flow

Function calculates the net present value of a series of cash receipts
and disbursements. The left argument is the interest rate and the
right a vector of cash flow items. Conventionally, the receipts are
positive and disbursement negative.

The theory is that a firm has a cost of capital, that is an average
rate of both the liabilities and equity.  An investment is evaluated
using that rate and the expected cash flow from the investment.  This
calculation can be made directly from that data. Some like internal
rate of return (see fin∆irr next) are more difficult. Usually one
must take the nth root of a number and therefore one has n possible
solutions. The finance workspace uses a converging iteration to find
one of those solutions.

@verbatim
      .1 fin∆netPresentValue ¯100000 10000 11000 12000 14000 15000, 10⍴18000
13408.07
@end verbatim

@end deffn

@deffn ∇ i ← guess fin∆irr vector

Internal rate of return.  That is the interest rate implied by a
vector of cash flows. This return is calculated iteratively using the
result of the last rate of return for the current calculation. One
must supply a guess to start the process.

@verbatim
      .1 fin∆irr ¯100000 10000 11000 12000 14000 15000, 10⍴18000
0.1222471688
@end verbatim

@end deffn


@section Dateflow

Dateflows are data structures that facilitate compound interest
calculations where cash flows are not annuities or simple
amounts. Each cash transfer, to or from, the investment is stored in
the dateflow array with it dollar amount.  The finance--dateflow
functions here assume that the date flow is complete, that is every
cash transfer to and from the investment is included.

With this data several things can be done to evaluate the
investment. Fin∆df∆irr will compute the internal rate of
return; fin∆df∆net_pv will compute the net present value of the
investment using the supplied interest rate; and fin∆df∆amortization
table will prepare a worksheet computing the future value of the
investment using the supplied interest rate.

Dateflows may be built using fin∆df∆init and fin∆df∆add.  Fin∆df∆show
displays the supplied dateflow.

For example, Apple common stock had a closing price of 66.82 per share
on November 30, 2019.  One year later it was 121.01.  During that year
Apple payed four dividends of 0.19 ((2020/02/07); 0.82 (2020/05/07);
0.21 (2020/08/07); and 0.19 (2020/11/07).  We construct a dateflow as
follows:

@verbatim
      apple←fin∆df∆init (date∆lillian 2019 11 30),¯66.82
      apple←apple fin∆df∆add (date∆lillian 2020 02 07) .19
      apple←apple fin∆df∆add (date∆lillian 2020 05 07) .82
      apple←apple fin∆df∆add (date∆lillian 2020 08 07) .21
      apple←apple fin∆df∆add (date∆lillian 2020 11 07) .19
      apple←apple fin∆df∆add (date∆lillian 2020 11 30) 121.01
      fin∆df∆show apple
2019/11/30         (66.82)
2020/02/07           0.19 
2020/05/07           0.82 
2020/08/07           0.21 
2020/11/07           0.19 
2020/11/30         121.01 
@end verbatim

with this date flow we compute the internal rate of return as follows:

@verbatim
      fin∆df∆irr apple .5 
0.6084386096
@end verbatim

Where apple is our date flow variable and .5 is an estimated interest
rate.  Any gues will do, the closer to the actuall return, the faster
the calculation.


@deffn ∇ df←fin∆df∆init item
Returns a dateflow.  item is a vector of lillian date and
amount. Generally this item is the amount of the initial ivestment and
is negative.
@end deffn

@deffn ∇ dateflow1 fin∆df∆add dateflow2

Returns two date flows.  Items in dateflow1 not in dateflow2 will be
added to dateflow2.  For items where the dates in dateflow1 match an item
in dateflow2, dateflow2's amount will be increased by dateflow1's
amount.

@end deffn

@deffn ∇ dateflow1 fin∆df∆subtract dateflow2

Returns dateflow1 less dateflow2.  That is each amount in dateflow2 is
negated and then added to dateflow1.

@end deffn

@deffn ∇ dateflow fin∆df∆multiply amount

The amounts in dateflow will be multiplied by the given amount

@end deffn

@deffn ∇ fin∆df∆show dateflow

Function will display a dateflow, converting the lillian dates to
yyyy/mm/dd.

@end deffn

@deffn ∇ fin∆dfp right_arg

Function returns true if the right argument is a dateflow.

@end deffn

@deffn ∇ fin∆df∆net_pv

Function returns the net present value of the date flow.  The right
argument is two items: First the dateflow and second the interest
rate.

@end deffn

@deffn ∇ fin∆df∆irr right_arg

Function returns the internal rate of return of a dateflow.  The right
argument is first the date flow and second an esimtate of the internal
rate of return.  The closer the estimate is to the actual rate, the
quicker the calculation.

@end deffn

@deffn ∇ fin∆df∆amortizationTable right_arg

Function returns an amortization table.  That is a table showing the
initial investment, assumed interest earned, each cash transfer and a
closing balance after each transfer as you would see in a pass book
for a savings account.

@end deffn
