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} {} irr (@var{p}, @var{i})
18 ## Return the internal rate of return of a series of payments @var{p}
19 ## from an initial investment @var{i} (i.e., the solution of
20 ## @code{npv (r, p) = i}. If the second argument is omitted, a value of
22 ## @seealso{npv, pv, rate}
25 function r = irr (p, i = 0)
27 if (nargin != 1 && nargin != 2)
29 elseif (! (isvector (p)))
30 error ("irr: p must be a vector");
31 elseif (! isscalar (i))
32 error ("irr: i must be a scalar");
36 f = @(x) npv (x, p) - i;