Skip to content

Commit 0db86ec

Browse files
committed
DOC: NPV: Document with decimal.Decimal
1 parent 4afacd4 commit 0db86ec

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

numpy_financial/_financial.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,20 @@ def npv(rate, values):
955955
[-2798.19, -3612.24],
956956
[-2884.3 , -3710.74]])
957957
958+
The NPV calculation also supports `decimal.Decimal` types, for example
959+
if using Decimal ``rates``:
960+
961+
>>> rates = [Decimal("0.00"), Decimal("0.05"), Decimal("0.10")]
962+
>>> cashflows = [[-4_000, 500, 800], [-5_000, 600, 900]]
963+
>>> npf.npv(rates, cashflows)
964+
array([[Decimal('-2700.0'), Decimal('-3500.0')],
965+
[Decimal('-2798.185941043083900226757370'),
966+
Decimal('-3612.244897959183673469387756')],
967+
[Decimal('-2884.297520661157024793388430'),
968+
Decimal('-3710.743801652892561983471074')]], dtype=object)
969+
970+
This also works for Decimal cashflows.
971+
958972
"""
959973
rates = np.atleast_1d(rate)
960974
values = np.atleast_2d(values)

0 commit comments

Comments
 (0)