Mercurial > octave
comparison scripts/finance/pv.m @ 3426:f8dde1807dee
[project @ 2000-01-13 08:40:00 by jwe]
author | jwe |
---|---|
date | Thu, 13 Jan 2000 08:40:53 +0000 |
parents | ae7adbb591e8 |
children | 3234a698073a |
comparison
equal
deleted
inserted
replaced
3425:8625164a0a39 | 3426:f8dde1807dee |
---|---|
1 ## Copyright (C) 1995, 1996 Kurt Hornik | 1 ## Copyright (C) 1995, 1996 Kurt Hornik |
2 ## | 2 ## |
3 ## This program is free software; you can redistribute it and/or modify | 3 ## This program is free software; you can redistribute it and/or modify |
4 ## it under the terms of the GNU General Public License as published by | 4 ## it under the terms of the GNU General Public License as published by |
5 ## the Free Software Foundation; either version 2, or (at your option) | 5 ## the Free Software Foundation; either version 2, or (at your option) |
6 ## any later version. | 6 ## any later version. |
7 ## | 7 ## |
8 ## This program is distributed in the hope that it will be useful, but | 8 ## This program is distributed in the hope that it will be useful, but |
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of | 9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 ## General Public License for more details. | 11 ## General Public License for more details. |
12 ## | 12 ## |
13 ## You should have received a copy of the GNU General Public License | 13 ## You should have received a copy of the GNU General Public License |
14 ## along with this file. If not, write to the Free Software Foundation, | 14 ## along with this file. If not, write to the Free Software Foundation, |
15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 15 ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
16 | 16 |
17 ## -*- texinfo -*- | 17 ## -*- texinfo -*- |
28 ## | 28 ## |
29 ## Note that the rate r is not specified in percent, i.e., one has to | 29 ## Note that the rate r is not specified in percent, i.e., one has to |
30 ## write 0.05 rather than 5 %. | 30 ## write 0.05 rather than 5 %. |
31 ## @end deftypefn | 31 ## @end deftypefn |
32 ## @seealso{pmt, nper, rate, and npv} | 32 ## @seealso{pmt, nper, rate, and npv} |
33 | 33 |
34 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> | 34 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
35 ## Description: Present value of an investment | 35 ## Description: Present value of an investment |
36 | 36 |
37 function v = pv (r, n, p, l, m) | 37 function v = pv (r, n, p, l, m) |
38 | 38 |
39 if ((nargin < 3) || (nargin > 5)) | 39 if ((nargin < 3) || (nargin > 5)) |
40 usage ("pv (r, n, p [, l] [, method])"); | 40 usage ("pv (r, n, p [, l] [, method])"); |
41 endif | 41 endif |
42 | 42 |
43 if !(is_scalar (r) && (r > -1)) | 43 if !(is_scalar (r) && (r > -1)) |
44 error ("pv: r must be a scalar > -1"); | 44 error ("pv: r must be a scalar > -1"); |
45 elseif !(is_scalar (n) && (n > 0)) | 45 elseif !(is_scalar (n) && (n > 0)) |
46 error ("pv: n must be a positive scalar"); | 46 error ("pv: n must be a positive scalar"); |
47 elseif !is_scalar (p) | 47 elseif !is_scalar (p) |
48 error ("pv: p must be a scalar."); | 48 error ("pv: p must be a scalar."); |
49 endif | 49 endif |
50 | 50 |
51 if (r != 0) | 51 if (r != 0) |
52 v = p * (1 - (1 + r)^(-n)) / r; | 52 v = p * (1 - (1 + r)^(-n)) / r; |
53 else | 53 else |
54 v = p * n; | 54 v = p * n; |
55 endif | 55 endif |
56 | 56 |
57 if (nargin > 3) | 57 if (nargin > 3) |
58 if (nargin == 5) | 58 if (nargin == 5) |
59 if !isstr (m) | 59 if !isstr (m) |
60 error ("pv: `method' must be a string"); | 60 error ("pv: `method' must be a string"); |
61 endif | 61 endif |
62 elseif isstr (l) | 62 elseif isstr (l) |
63 m = l; | 63 m = l; |
64 l = 0; | 64 l = 0; |
65 else | 65 else |
72 v = v + pvl (r, n, l); | 72 v = v + pvl (r, n, l); |
73 else | 73 else |
74 error ("pv: l must be a scalar"); | 74 error ("pv: l must be a scalar"); |
75 endif | 75 endif |
76 endif | 76 endif |
77 | 77 |
78 endfunction | 78 endfunction |
79 | 79 |