13
13
from __future__ import division , absolute_import , print_function
14
14
15
15
from decimal import Decimal
16
- import functools
17
16
18
17
import numpy as np
19
- from numpy .core import overrides
20
-
21
-
22
- array_function_dispatch = functools .partial (
23
- overrides .array_function_dispatch , module = 'numpy' )
24
18
25
19
26
20
__all__ = ['fv' , 'pmt' , 'nper' , 'ipmt' , 'ppmt' , 'pv' , 'rate' ,
@@ -45,11 +39,6 @@ def _convert_when(when):
45
39
return [_when_to_num [x ] for x in when ]
46
40
47
41
48
- def _fv_dispatcher (rate , nper , pmt , pv , when = None ):
49
- return (rate , nper , pmt , pv )
50
-
51
-
52
- @array_function_dispatch (_fv_dispatcher )
53
42
def fv (rate , nper , pmt , pv , when = 'end' ):
54
43
"""
55
44
Compute the future value.
@@ -142,11 +131,6 @@ def fv(rate, nper, pmt, pv, when='end'):
142
131
return - (pv * temp + pmt * fact )
143
132
144
133
145
- def _pmt_dispatcher (rate , nper , pv , fv = None , when = None ):
146
- return (rate , nper , pv , fv )
147
-
148
-
149
- @array_function_dispatch (_pmt_dispatcher )
150
134
def pmt (rate , nper , pv , fv = 0 , when = 'end' ):
151
135
"""
152
136
Compute the payment against loan principal plus interest.
@@ -242,11 +226,6 @@ def pmt(rate, nper, pv, fv=0, when='end'):
242
226
return - (fv + pv * temp ) / fact
243
227
244
228
245
- def _nper_dispatcher (rate , pmt , pv , fv = None , when = None ):
246
- return (rate , pmt , pv , fv )
247
-
248
-
249
- @array_function_dispatch (_nper_dispatcher )
250
229
def nper (rate , pmt , pv , fv = 0 , when = 'end' ):
251
230
"""
252
231
Compute the number of periodic payments.
@@ -319,11 +298,6 @@ def nper(rate, pmt, pv, fv=0, when='end'):
319
298
return np .where (rate == 0 , A , B )
320
299
321
300
322
- def _ipmt_dispatcher (rate , per , nper , pv , fv = None , when = None ):
323
- return (rate , per , nper , pv , fv )
324
-
325
-
326
- @array_function_dispatch (_ipmt_dispatcher )
327
301
def ipmt (rate , per , nper , pv , fv = 0 , when = 'end' ):
328
302
"""
329
303
Compute the interest portion of a payment.
@@ -433,11 +407,6 @@ def _rbl(rate, per, pmt, pv, when):
433
407
return fv (rate , (per - 1 ), pmt , pv , when )
434
408
435
409
436
- def _ppmt_dispatcher (rate , per , nper , pv , fv = None , when = None ):
437
- return (rate , per , nper , pv , fv )
438
-
439
-
440
- @array_function_dispatch (_ppmt_dispatcher )
441
410
def ppmt (rate , per , nper , pv , fv = 0 , when = 'end' ):
442
411
"""
443
412
Compute the payment against loan principal.
@@ -467,11 +436,6 @@ def ppmt(rate, per, nper, pv, fv=0, when='end'):
467
436
return total - ipmt (rate , per , nper , pv , fv , when )
468
437
469
438
470
- def _pv_dispatcher (rate , nper , pmt , fv = None , when = None ):
471
- return (rate , nper , nper , pv , fv )
472
-
473
-
474
- @array_function_dispatch (_pv_dispatcher )
475
439
def pv (rate , nper , pmt , fv = 0 , when = 'end' ):
476
440
"""
477
441
Compute the present value.
@@ -586,19 +550,13 @@ def _g_div_gp(r, n, p, x, y, w):
586
550
return g / gp
587
551
588
552
589
- def _rate_dispatcher (nper , pmt , pv , fv , when = None , guess = None , tol = None ,
590
- maxiter = None ):
591
- return (nper , pmt , pv , fv )
592
-
593
-
594
553
# Use Newton's iteration until the change is less than 1e-6
595
554
# for all values or a maximum of 100 iterations is reached.
596
555
# Newton's rule is
597
556
# r_{n+1} = r_{n} - g(r_n)/g'(r_n)
598
557
# where
599
558
# g(r) is the formula
600
559
# g'(r) is the derivative with respect to r.
601
- @array_function_dispatch (_rate_dispatcher )
602
560
def rate (nper , pmt , pv , fv , when = 'end' , guess = None , tol = None , maxiter = 100 ):
603
561
"""
604
562
Compute the rate of interest per period.
@@ -671,11 +629,6 @@ def rate(nper, pmt, pv, fv, when='end', guess=None, tol=None, maxiter=100):
671
629
return rn
672
630
673
631
674
- def _irr_dispatcher (values ):
675
- return (values ,)
676
-
677
-
678
- @array_function_dispatch (_irr_dispatcher )
679
632
def irr (values ):
680
633
"""
681
634
Return the Internal Rate of Return (IRR).
@@ -756,11 +709,6 @@ def irr(values):
756
709
return rate
757
710
758
711
759
- def _npv_dispatcher (rate , values ):
760
- return (values ,)
761
-
762
-
763
- @array_function_dispatch (_npv_dispatcher )
764
712
def npv (rate , values ):
765
713
"""
766
714
Returns the NPV (Net Present Value) of a cash flow series.
@@ -833,11 +781,6 @@ def npv(rate, values):
833
781
return (values / (1 + rate )** np .arange (0 , len (values ))).sum (axis = 0 )
834
782
835
783
836
- def _mirr_dispatcher (values , finance_rate , reinvest_rate ):
837
- return (values ,)
838
-
839
-
840
- @array_function_dispatch (_mirr_dispatcher )
841
784
def mirr (values , finance_rate , reinvest_rate ):
842
785
"""
843
786
Modified internal rate of return.
0 commit comments