home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts / finance / pmt.m < prev    next >
Text File  |  1997-02-19  |  2KB  |  74 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:  pmt (r, n, a [, l] [, method])
  18. ##
  19. ## Compute the amount of periodic payment necessary to amortize a loan
  20. ## of amount a with interest rate r in n periods.
  21. ##
  22. ## With the optional scalar argument l, one can specify an initial
  23. ## lump-sum payment. With the optional string argument `method', one can
  24. ## specify whether payments are made at the end ("e", default) or at the
  25. ## beginning ("b") of each period.
  26. ##
  27. ## See also:  pv, nper, rate
  28.   
  29. ## Author:  KH <Kurt.Hornik@ci.tuwien.ac.at>
  30. ## Description:  Amount of periodic payment needed to amortize a loan
  31.  
  32. function p = pmt (r, n, a, l, m)
  33.   
  34.   if ((nargin < 3) || (nargin > 5))
  35.     usage ("pmt (r, n, a [, l] [, method])");
  36.   endif
  37.   
  38.   if !(is_scalar (r) && (r > -1))
  39.     error ("pmt:  rate must be a scalar > -1");
  40.   elseif !(is_scalar (n) && (n > 0))
  41.     error ("pmt:  n must be a positive scalar");
  42.   elseif !(is_scalar (a) && (a > 0))
  43.     error ("pmt:  a must be a positive scalar.");
  44.   endif
  45.   
  46.   if (nargin == 5)
  47.     if !isstr (m)
  48.       error ("pmt:  `method' must be a string");
  49.     endif
  50.   elseif (nargin == 4)
  51.     if isstr (l)
  52.       m = l;
  53.       l = 0;
  54.     else
  55.       m = "e";
  56.     endif
  57.   else
  58.     l = 0;
  59.     m = "e";
  60.   endif
  61.   
  62.   p = r * (a - l * (1 + r)^(-n)) / (1 - (1 + r)^(-n));
  63.   
  64.   if strcmp (m, "b")
  65.     p = p / (1 + r);
  66.   endif
  67.   
  68.   
  69. endfunction
  70.       
  71.  
  72.  
  73.  
  74.