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} {} pmt (@var{r}, @var{n}, @var{a}, @var{l}, @var{method})
18 ## Return the amount of periodic payment necessary to amortize a loan
19 ## of amount a with interest rate @var{r} in @var{n} periods.
21 ## The optional argument @var{l} may be used to specify a terminal
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.
27 ## @seealso{pv, nper, rate}
30 function p = pmt (r, n, a, l, m)
32 if (nargin < 3 || nargin > 5)
36 if (! (isscalar (r) && r > -1))
37 error ("pmt: rate must be a scalar > -1");
38 elseif (! (isscalar (n) && n > 0))
39 error ("pmt: n must be a positive scalar");
40 elseif (! (isscalar (a) && a > 0))
41 error ("pmt: a must be a positive scalar");
46 error ("pmt: `method' must be a string");
60 p = r * (a - l * (1 + r)^(-n)) / (1 - (1 + r)^(-n));