home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / finance / pv.m < prev    next >
Text File  |  1997-02-19  |  2KB  |  80 lines

  1. ## Copyright (C) 1995, 1996  Kurt Hornik
  2. ## 
  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
  5. ## the Free Software Foundation; either version 2, or (at your option)
  6. ## any later version.
  7. ## 
  8. ## This program is distributed in the hope that it will be useful, but
  9. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11. ## General Public License for more details. 
  12. ## 
  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,
  15. ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16.  
  17. ## usage:  pv (r, n, p [, l] [, method])
  18. ##
  19. ## Returns the present value of an investment that will pay off p for n
  20. ## consecutive periods, assuming an interest r.
  21. ##
  22. ## With the optional scalar argument l, one can specify an additional
  23. ## lump-sum payment made at the end of n periods.
  24. ##
  25. ## With the optional string argument `method', one can specify whether
  26. ## payments are made at the end ("e", default) or at the beginning ("b")
  27. ## of each period.
  28. ##
  29. ## Note that the rate r is not specified in percent, i.e., one has to
  30. ## write 0.05 rather than 5 %.
  31. ##
  32. ## See also:  pmt, nper, rate;  npv.
  33.   
  34. ## Author:  KH <Kurt.Hornik@ci.tuwien.ac.at>
  35. ## Description:  Present value of an investment
  36.  
  37. function v = pv (r, n, p, l, m)
  38.   
  39.   if ((nargin < 3) || (nargin > 5))
  40.     usage ("pv (r, n, p [, l] [, method])");
  41.   endif
  42.   
  43.   if !(is_scalar (r) && (r > -1))
  44.     error ("pv:  r must be a scalar > -1");
  45.   elseif !(is_scalar (n) && (n > 0))
  46.     error ("pv:  n must be a positive scalar");
  47.   elseif !is_scalar (p)
  48.     error ("pv:  p must be a scalar.");
  49.   endif
  50.   
  51.   if (r != 0)
  52.     v = p * (1 - (1 + r)^(-n)) / r;
  53.   else
  54.     v = p * n;
  55.   endif
  56.   
  57.   if (nargin > 3)
  58.     if (nargin == 5)
  59.       if !isstr (m)
  60.     error ("pv:  `method' must be a string");
  61.       endif
  62.     elseif isstr (l)
  63.       m = l;
  64.       l = 0;
  65.     else
  66.       m = "e";
  67.     endif
  68.     if strcmp (m, "b")
  69.       v = v * (1 + r);
  70.     endif
  71.     if is_scalar (l)
  72.       v = v + pvl (r, n, l);
  73.     else
  74.       error ("pv:  l must be a scalar");
  75.     endif
  76.   endif
  77.   
  78. endfunction
  79.       
  80.