[Numpy-svn] r4990 - in trunk/numpy/lib: . tests

numpy-svn at scipy.org numpy-svn at scipy.org
Tue Apr 8 16:43:09 EDT 2008


Author: oliphant
Date: 2008-04-08 15:43:07 -0500 (Tue, 08 Apr 2008)
New Revision: 4990

Modified:
   trunk/numpy/lib/financial.py
   trunk/numpy/lib/tests/test_financial.py
Log:
Fix doc-tests for financial.py so they don't rely on floating-point exactness.  Start filling in final function.

Modified: trunk/numpy/lib/financial.py
===================================================================
--- trunk/numpy/lib/financial.py	2008-04-08 18:49:18 UTC (rev 4989)
+++ trunk/numpy/lib/financial.py	2008-04-08 20:43:07 UTC (rev 4990)
@@ -139,11 +139,13 @@
 """
 
 def ipmt(rate, per, nper, pv, fv=0.0, when='end'):
+    total = pmt(rate, nper, pv, fv, when)
+    # Now, compute the nth step in the amortization
     raise NotImplementedError
 
-
 def ppmt(rate, per, nper, pv, fv=0.0, when='end'):
-    raise NotImplementedError
+    total = pmt(rate, nper, pv, fv, when)
+    return total - ipmt(rate, per, nper, pv, fv, when)
 
 def pv(rate, nper, pmt, fv=0.0, when='end'):
     """Number of periods found by solving the equation

Modified: trunk/numpy/lib/tests/test_financial.py
===================================================================
--- trunk/numpy/lib/tests/test_financial.py	2008-04-08 18:49:18 UTC (rev 4989)
+++ trunk/numpy/lib/tests/test_financial.py	2008-04-08 20:43:07 UTC (rev 4990)
@@ -1,32 +1,32 @@
 """
-from numpy import *
+>>> from numpy import rate, irr, pv, fv, pmt, nper, npv, mirr, round
 
->>> rate(10,0,-3500,10000)
-0.11069085371426901
+>>> round(rate(10,0,-3500,10000),4)==0.1107
+True
 
->>> irr([-150000, 15000, 25000, 35000, 45000, 60000])
-0.052432888859414106
+>>> round(irr([-150000, 15000, 25000, 35000, 45000, 60000]),4)==0.0524
+True
 
->>> pv(0.07,20,12000,0)
--127128.17094619398
+>>> round(pv(0.07,20,12000,0),2) == -127128.17
+True
 
->>> fv(0.075, 20, -2000,0,0)
-86609.362673042924
+>>> round(fv(0.075, 20, -2000,0,0),2) == 86609.36
+True
 
->>> pmt(0.08/12,5*12,15000)
--304.14591432620773
+>>> round(pmt(0.08/12,5*12,15000),3) == -304.146
+True
 
->>> nper(0.075,-2000,0,100000.)
-21.544944197323336
+>>> round(nper(0.075,-2000,0,100000.),2) == 21.54
+True
 
->>> npv(0.05,[-15000,1500,2500,3500,4500,6000])
-117.04271900089589
+>>> round(npv(0.05,[-15000,1500,2500,3500,4500,6000]),2) == 117.04
+True
 
->>> mirr([-4500,-800,800,800,600,600,800,800,700,3000],0.08,0.055)
-0.066471183500200537
+>>> round(mirr([-4500,-800,800,800,600,600,800,800,700,3000],0.08,0.055),4) == 0.0665
+True
 
->>> mirr([-120000,39000,30000,21000,37000,46000],0.10,0.12)
-0.13439316981387006
+>>> round(mirr([-120000,39000,30000,21000,37000,46000],0.10,0.12),4)==0.1344
+True
 """
 
 from numpy.testing import *




More information about the Numpy-svn mailing list