home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / finance / fv.m next >
Text File  |  1999-04-29  |  2KB  |  77 lines

  1. ## Copyright (C) 1995, 1996, 1997  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:  fv (r, n, p [, l] [, method])
  18. ##
  19. ## Returns the future value at the end of period n of an investment
  20. ## which consisting of n payments of p in each period, assuming an
  21. ## interest rate r.
  22. ##
  23. ## With the optional scalar argument l, one can specify an additional
  24. ## lump-sum payment. With the optional argument `method', one can
  25. ## specify whether the payments are made at the end ("e", default) or at
  26. ## the beginning ("b") of each period.
  27. ##
  28. ## Note that the rate r is not specified in percent, i.e., one has to
  29. ## write 0.05 rather than 5 %.
  30.   
  31. ## Author:  KH <Kurt.Hornik@ci.tuwien.ac.at>
  32. ## Description:  Future value of an investment
  33.  
  34. function v = fv (r, n, p, l, m)
  35.   
  36.   if ((nargin < 3) || (nargin > 5))
  37.     usage ("fv (r, n, p [, l] [, method])");
  38.   endif
  39.   
  40.   if !(is_scal (r) && (r > -1))
  41.     error ("fv:  r must be a scalar > -1");
  42.   elseif !(is_scal (n) && (n > 0))
  43.     error ("fv:  n must be a positive scalar");
  44.   elseif !is_scal (p)
  45.     error ("fv:  p must be a scalar.");
  46.   endif
  47.   
  48.   if (r != 0)
  49.     v = p * ((1 + r)^n - 1) / r;
  50.   else
  51.     v = p * n;
  52.   endif
  53.   
  54.   if (nargin > 3)
  55.     if (nargin == 5)
  56.       if !isstr (m)
  57.         error ("fv:  `method' must be a string");
  58.       endif
  59.     elseif isstr (l)
  60.       m = l;
  61.       l = 0;
  62.     else
  63.       m = "e";
  64.     endif
  65.     if strcmp (m, "b")
  66.       v = v * (1 + r);
  67.     endif
  68.     if is_scal (l)
  69.       v = v + fvl (r, n, l);
  70.     else
  71.       error ("fv:  l must be a scalar");
  72.     endif
  73.   endif
  74.   
  75. endfunction
  76.       
  77.