Skip to content

Commit 0a3d64c

Browse files
Kai-StriegaWarrenWeckesser
authored andcommitted
STY: Group terms in _g_div_gp helper function.
1 parent 485d2ec commit 0a3d64c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

numpy_financial/_financial.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
'start': 1,
3434
'finish': 0}
3535

36+
3637
def _convert_when(when):
3738
# Test to see if when has already been converted to ndarray
3839
# This will happen if one function calls another, for example ppmt
@@ -571,12 +572,18 @@ def pv(rate, nper, pmt, fv=0, when='end'):
571572
# p*((r + 1)^n - 1)*(r*w + 1)/r^2 + n*p*(r + 1)^(n - 1)*(r*w + 1)/r +
572573
# p*((r + 1)^n - 1)*w/r)
573574

575+
574576
def _g_div_gp(r, n, p, x, y, w):
577+
# Evaluate g(r_n)/g'(r_n), where g =
578+
# fv + pv*(1+rate)**nper + pmt*(1+rate*when)/rate * ((1+rate)**nper - 1)
575579
t1 = (r+1)**n
576580
t2 = (r+1)**(n-1)
577-
return ((y + t1*x + p*(t1 - 1)*(r*w + 1)/r) /
578-
(n*t2*x - p*(t1 - 1)*(r*w + 1)/(r**2) + n*p*t2*(r*w + 1)/r +
579-
p*(t1 - 1)*w/r))
581+
g = y + t1*x + p*(t1 - 1) * (r*w + 1) / r
582+
gp = (n*t2*x
583+
- p*(t1 - 1) * (r*w + 1) / (r**2)
584+
+ n*p*t2 * (r*w + 1) / r
585+
+ p*(t1 - 1) * w/r)
586+
return g / gp
580587

581588

582589
def _rate_dispatcher(nper, pmt, pv, fv, when=None, guess=None, tol=None,

0 commit comments

Comments
 (0)