]> Creatis software - CreaPhase.git/blob - octave_packages/financial-0.4.0/pvl.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / financial-0.4.0 / pvl.m
1 ## Copyright (C) 1995-1998, 2000, 2002, 2005-2007 Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
2 ##
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
6 ## version.
7 ##
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
11 ## details.
12 ##
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/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {@var{v} =} pvl (@var{r}, @var{n}, @var{p})
18 ## Return the present value @var{v} of an investment that will pay off @var{p}
19 ## in one lump sum at the end of @var{n} periods, given the interest
20 ## rate @var{r}.
21 ##
22 ## Note that the rate @var{r} is specified as a fraction (i.e., 0.05,
23 ## not 5 percent).
24 ## @end deftypefn
25
26 function v = pvl (r, n, p)
27
28   if (nargin != 3)
29     print_usage ();
30   endif
31
32   if (! (isscalar (r) && (r > -1)))
33     error ("pvl: r has to be a scalar > -1");
34   elseif (! (isscalar (n) && n > 0))
35     error ("pvl: n has to be a positive scalar");
36   elseif (! isscalar (p))
37     error ("pvl: p has to be a scalar");
38   endif
39
40   v = p / (1 + r)^n;
41
42 endfunction