3191
|
1 ## Copyright (C) 1995, 1996, 1997 Kurt Hornik |
3426
|
2 ## |
3922
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
3426
|
9 ## |
3922
|
10 ## Octave is distributed in the hope that it will be useful, but |
3191
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3426
|
13 ## General Public License for more details. |
|
14 ## |
3191
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
3191
|
18 |
3426
|
19 ## -*- texinfo -*- |
3439
|
20 ## @deftypefn {Function File} {} pmt (@var{r}, @var{n}, @var{a}, @var{l}, @var{method}) |
|
21 ## Return the amount of periodic payment necessary to amortize a loan |
3407
|
22 ## of amount a with interest rate @var{r} in @var{n} periods. |
3191
|
23 ## |
3832
|
24 ## The optional argument @var{l} may be used to specify a terminal |
3439
|
25 ## lump-sum payment. |
|
26 ## |
|
27 ## The optional argument @var{method} may be used to specify whether |
|
28 ## payments are made at the end (@var{"e"}, default) or at the beginning |
|
29 ## (@var{"b"}) of each period. |
5642
|
30 ## @seealso{pv, nper, rate} |
3407
|
31 ## @end deftypefn |
3426
|
32 |
5428
|
33 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3458
|
34 ## Description: Amount of periodic payment needed to amortize a loan |
3191
|
35 |
|
36 function p = pmt (r, n, a, l, m) |
3426
|
37 |
3831
|
38 if (nargin < 3 || nargin > 5) |
6046
|
39 print_usage (); |
3191
|
40 endif |
3426
|
41 |
4030
|
42 if (! (isscalar (r) && r > -1)) |
3458
|
43 error ("pmt: rate must be a scalar > -1"); |
4030
|
44 elseif (! (isscalar (n) && n > 0)) |
3458
|
45 error ("pmt: n must be a positive scalar"); |
4030
|
46 elseif (! (isscalar (a) && a > 0)) |
3458
|
47 error ("pmt: a must be a positive scalar"); |
3191
|
48 endif |
3426
|
49 |
3191
|
50 if (nargin == 5) |
5443
|
51 if (! ischar (m)) |
3458
|
52 error ("pmt: `method' must be a string"); |
3191
|
53 endif |
|
54 elseif (nargin == 4) |
5443
|
55 if (ischar (l)) |
3191
|
56 m = l; |
|
57 l = 0; |
|
58 else |
|
59 m = "e"; |
|
60 endif |
|
61 else |
|
62 l = 0; |
|
63 m = "e"; |
|
64 endif |
3426
|
65 |
3191
|
66 p = r * (a - l * (1 + r)^(-n)) / (1 - (1 + r)^(-n)); |
3426
|
67 |
3456
|
68 if (strcmp (m, "b")) |
3191
|
69 p = p / (1 + r); |
|
70 endif |
3426
|
71 |
|
72 |
3191
|
73 endfunction |
|
74 |
|
75 |
|
76 |
3426
|
77 |