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 |
3191
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## 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 |
3922
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
3191
|
19 |
3426
|
20 ## -*- texinfo -*- |
3439
|
21 ## @deftypefn {Function File} {} pmt (@var{r}, @var{n}, @var{a}, @var{l}, @var{method}) |
|
22 ## Return the amount of periodic payment necessary to amortize a loan |
3407
|
23 ## of amount a with interest rate @var{r} in @var{n} periods. |
3191
|
24 ## |
3832
|
25 ## The optional argument @var{l} may be used to specify a terminal |
3439
|
26 ## lump-sum payment. |
|
27 ## |
|
28 ## The optional argument @var{method} may be used to specify whether |
|
29 ## payments are made at the end (@var{"e"}, default) or at the beginning |
|
30 ## (@var{"b"}) of each period. |
3407
|
31 ## @end deftypefn |
5053
|
32 ## |
3408
|
33 ## @seealso{pv, nper, and rate} |
3426
|
34 |
5428
|
35 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
3458
|
36 ## Description: Amount of periodic payment needed to amortize a loan |
3191
|
37 |
|
38 function p = pmt (r, n, a, l, m) |
3426
|
39 |
3831
|
40 if (nargin < 3 || nargin > 5) |
3456
|
41 usage ("pmt (r, n, a, l, method)"); |
3191
|
42 endif |
3426
|
43 |
4030
|
44 if (! (isscalar (r) && r > -1)) |
3458
|
45 error ("pmt: rate must be a scalar > -1"); |
4030
|
46 elseif (! (isscalar (n) && n > 0)) |
3458
|
47 error ("pmt: n must be a positive scalar"); |
4030
|
48 elseif (! (isscalar (a) && a > 0)) |
3458
|
49 error ("pmt: a must be a positive scalar"); |
3191
|
50 endif |
3426
|
51 |
3191
|
52 if (nargin == 5) |
3456
|
53 if (! isstr (m)) |
3458
|
54 error ("pmt: `method' must be a string"); |
3191
|
55 endif |
|
56 elseif (nargin == 4) |
3456
|
57 if (isstr (l)) |
3191
|
58 m = l; |
|
59 l = 0; |
|
60 else |
|
61 m = "e"; |
|
62 endif |
|
63 else |
|
64 l = 0; |
|
65 m = "e"; |
|
66 endif |
3426
|
67 |
3191
|
68 p = r * (a - l * (1 + r)^(-n)) / (1 - (1 + r)^(-n)); |
3426
|
69 |
3456
|
70 if (strcmp (m, "b")) |
3191
|
71 p = p / (1 + r); |
|
72 endif |
3426
|
73 |
|
74 |
3191
|
75 endfunction |
|
76 |
|
77 |
|
78 |
3426
|
79 |