Skip to content

Commit b8592cf

Browse files
committed
MAINT: NPV: Remove typed constants
These were originally added when the code was written as one function without numba. As numba is now being used, and the functions are therefore seperated. This is no longer required and makes the code more complex.
1 parent 04af33f commit b8592cf

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

numpy_financial/_financial.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -857,23 +857,23 @@ def irr(values, *, guess=None, tol=1e-12, maxiter=100, raise_exceptions=False):
857857

858858

859859
@nb.njit(parallel=True)
860-
def _npv_native(rates, values, out, zero, one):
860+
def _npv_native(rates, values, out):
861861
for i in nb.prange(rates.shape[0]):
862862
for j in nb.prange(values.shape[0]):
863-
acc = zero
863+
acc = 0.0
864864
for t in range(values.shape[1]):
865-
acc += values[j, t] / ((one + rates[i]) ** t)
865+
acc += values[j, t] / ((1.0 + rates[i]) ** t)
866866
out[i, j] = acc
867867

868868

869869
# We require ``forceobj=True`` here to support decimal.Decimal types
870870
@nb.jit(forceobj=True)
871-
def _npv_decimal(rates, values, out, zero, one):
871+
def _npv_decimal(rates, values, out):
872872
for i in range(rates.shape[0]):
873873
for j in range(values.shape[0]):
874-
acc = zero
874+
acc = Decimal("0.0")
875875
for t in range(values.shape[1]):
876-
acc += values[j, t] / ((one + rates[i]) ** t)
876+
acc += values[j, t] / ((Decimal("1.0") + rates[i]) ** t)
877877
out[i, j] = acc
878878

879879

@@ -972,16 +972,14 @@ def npv(rate, values):
972972
if dtype == Decimal:
973973
rates = _to_decimal_array_1d(rates)
974974
values = _to_decimal_array_2d(values)
975-
zero = dtype("0.0")
976-
one = dtype("1.0")
977975

978976
shape = _get_output_array_shape(rates, values)
979977
out = np.empty(shape=shape, dtype=dtype)
980978

981979
if dtype == Decimal:
982-
_npv_decimal(rates, values, out, zero, one)
980+
_npv_decimal(rates, values, out)
983981
else:
984-
_npv_native(rates, values, out, zero, one)
982+
_npv_native(rates, values, out)
985983

986984
return _return_ufunc_like(out)
987985

0 commit comments

Comments
 (0)