@@ -306,35 +306,33 @@ def nper(rate, pmt, pv, fv=0, when='end'):
306306 The same analysis could be done with several different interest rates
307307 and/or payments and/or total amounts to produce an entire table.
308308
309- >>> npf.nper(*(np.ogrid[0.07/12: 0.08/12: 0.01/12,
310- ... -150 : -99 : 50 ,
311- ... 8000 : 9001 : 1000]))
312- array([[[ 64.07334877, 74.06368256],
313- [108.07548412, 127.99022654]],
309+ >>> rates = [0.05, 0.06, 0.07]
310+ >>> payments = [100, 200, 300]
311+ >>> amounts = [7_000, 8_000, 9_000]
312+ >>> npf.nper(rates, payments, amounts).round(3)
313+ array([[[-30.827, -32.987, -34.94 ],
314+ [-20.734, -22.517, -24.158],
315+ [-15.847, -17.366, -18.78 ]],
314316 <BLANKLINE>
315- [[ 66.12443902, 76.87897353],
316- [114.70165583, 137.90124779]]])
317+ [[-28.294, -30.168, -31.857],
318+ [-19.417, -21.002, -22.453],
319+ [-15.025, -16.398, -17.67 ]],
320+ <BLANKLINE>
321+ [[-26.234, -27.891, -29.381],
322+ [-18.303, -19.731, -21.034],
323+ [-14.311, -15.566, -16.722]]])
317324 """
318325 when = _convert_when (when )
319- rate , pmt , pv , fv , when = np .broadcast_arrays (rate , pmt , pv , fv , when )
320- nper_array = np .empty_like (rate , dtype = np .float64 )
321-
322- zero = rate == 0
323- nonzero = ~ zero
324-
325- with np .errstate (divide = 'ignore' ):
326- # Infinite numbers of payments are okay, so ignore the
327- # potential divide by zero.
328- nper_array [zero ] = - (fv [zero ] + pv [zero ]) / pmt [zero ]
329-
330- nonzero_rate = rate [nonzero ]
331- z = pmt [nonzero ] * (1 + nonzero_rate * when [nonzero ]) / nonzero_rate
332- nper_array [nonzero ] = (
333- np .log ((- fv [nonzero ] + z ) / (pv [nonzero ] + z ))
334- / np .log (1 + nonzero_rate )
335- )
336-
337- return nper_array
326+ rates = np .atleast_1d (rate ).astype (np .float64 )
327+ pmts = np .atleast_1d (pmt ).astype (np .float64 )
328+ pvs = np .atleast_1d (pv ).astype (np .float64 )
329+ fvs = np .atleast_1d (fv ).astype (np .float64 )
330+ whens = np .atleast_1d (when ).astype (np .float64 )
331+
332+ out_shape = _get_output_array_shape (rates , pmts , pvs , fvs , whens )
333+ out = np .empty (out_shape )
334+ _cfinancial .nper (rates , pmts , pvs , fvs , whens , out )
335+ return _ufunc_like (out )
338336
339337
340338def _value_like (arr , value ):
0 commit comments