1 ## Copyright (C) 1995-1996, 1998, 2000, 2002, 2004-2007 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {} pv (@var{r}, @var{n}, @var{p}, @var{l}, @var{method})
18 ## Returns the present value of an investment that will pay off @var{p} for @var{n}
19 ## consecutive periods, assuming an interest @var{r}.
21 ## The optional argument @var{l} may be used to specify an additional
22 ## lump-sum payment made at the end of @var{n} periods.
24 ## The optional argument @var{method} may be used to specify whether
25 ## payments are made at the end (@code{"e"}, default) or at the
26 ## beginning (@code{"b"}) of each period.
28 ## Note that the rate @var{r} is specified as a fraction (i.e., 0.05,
30 ## @seealso{pmt, nper, rate, npv}
33 function v = pv (r, n, p, l, m)
35 if (nargin < 3 || nargin > 5)
39 if (! (isscalar (r) && r > -1))
40 error ("pv: r must be a scalar > -1");
41 elseif (! (isscalar (n) && n > 0))
42 error ("pv: n must be a positive scalar");
43 elseif (! isscalar (p))
44 error ("pv: p must be a scalar");
48 v = p * (1 - (1 + r)^(-n)) / r;
56 error ("pv: `method' must be a string");
68 v = v + pvl (r, n, l);
70 error ("pv: l must be a scalar");