1 ## Copyright (C) 1995-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} {} nper (@var{r}, @var{p}, @var{a}, @var{l}, @var{method})
18 ## Return the number of regular payments of @var{p} necessary to
19 ## amortize @var{a} loan of amount @var{a} and interest @var{r}.
21 ## The optional argument @var{l} may be used to specify an additional
22 ## lump-sum payment of @var{l} made at the end of the amortization time.
24 ## The optional argument @var{method} may be used to specify whether
25 ## payments are made at the end (@var{"e"}, default) or at the beginning
26 ## (@var{"b"}) of each period.
28 ## Note that the rate @var{r} is specified as a fraction (i.e., 0.05,
30 ## @seealso{pv, pmt, rate, npv}
33 function n = nper (r, p, a, l, m)
35 if (nargin < 3 || nargin > 5)
39 if (! (isscalar (r) && r > -1))
40 error ("nper: r must be a scalar > -1");
41 elseif (! isscalar (p))
42 error ("nper: p must be a scalar");
43 elseif (! isscalar (a))
44 error ("nper: a must be a scalar");
49 error ("nper: `method' must be a string");
67 q = (p - r * a) / (p - r * l);
70 n = - log (q) / log (1 + r);