@@ -111,11 +111,14 @@ def fv(rate, nper, pmt, pv, when='end'):
111
111
112
112
Examples
113
113
--------
114
+ >>> import numpy as np
115
+ >>> import numpy_financial as nf
116
+
114
117
What is the future value after 10 years of saving $100 now, with
115
118
an additional monthly savings of $100. Assume the interest rate is
116
119
5% (annually) compounded monthly?
117
120
118
- >>> np .fv(0.05/12, 10*12, -100, -100)
121
+ >>> nf .fv(0.05/12, 10*12, -100, -100)
119
122
15692.928894335748
120
123
121
124
By convention, the negative sign represents cash flow out (i.e. money not
@@ -126,7 +129,7 @@ def fv(rate, nper, pmt, pv, when='end'):
126
129
compare different interest rates from the example above.
127
130
128
131
>>> a = np.array((0.05, 0.06, 0.07))/12
129
- >>> np .fv(a, 10*12, -100, -100)
132
+ >>> nf .fv(a, 10*12, -100, -100)
130
133
array([ 15692.92889434, 16569.87435405, 17509.44688102]) # may vary
131
134
132
135
"""
@@ -215,10 +218,12 @@ def pmt(rate, nper, pv, fv=0, when='end'):
215
218
216
219
Examples
217
220
--------
221
+ >>> import numpy_financial as nf
222
+
218
223
What is the monthly payment needed to pay off a $200,000 loan in 15
219
224
years at an annual interest rate of 7.5%?
220
225
221
- >>> np .pmt(0.075/12, 12*15, 200000)
226
+ >>> nf .pmt(0.075/12, 12*15, 200000)
222
227
-1854.0247200054619
223
228
224
229
In order to pay-off (i.e., have a future-value of 0) the $200,000 obtained
@@ -272,18 +277,21 @@ def nper(rate, pmt, pv, fv=0, when='end'):
272
277
273
278
Examples
274
279
--------
280
+ >>> import numpy as np
281
+ >>> import numpy_financial as nf
282
+
275
283
If you only had $150/month to pay towards the loan, how long would it take
276
284
to pay-off a loan of $8,000 at 7% annual interest?
277
285
278
- >>> print(np.round(np .nper(0.07/12, -150, 8000), 5))
286
+ >>> print(np.round(nf .nper(0.07/12, -150, 8000), 5))
279
287
64.07335
280
288
281
289
So, over 64 months would be required to pay off the loan.
282
290
283
291
The same analysis could be done with several different interest rates
284
292
and/or payments and/or total amounts to produce an entire table.
285
293
286
- >>> np .nper(*(np.ogrid[0.07/12: 0.08/12: 0.01/12,
294
+ >>> nf .nper(*(np.ogrid[0.07/12: 0.08/12: 0.01/12,
287
295
... -150 : -99 : 50 ,
288
296
... 8000 : 9001 : 1000]))
289
297
array([[[ 64.07334877, 74.06368256],
@@ -356,6 +364,9 @@ def ipmt(rate, per, nper, pv, fv=0, when='end'):
356
364
357
365
Examples
358
366
--------
367
+ >>> import numpy as np
368
+ >>> import numpy_financial as nf
369
+
359
370
What is the amortization schedule for a 1 year loan of $2500 at
360
371
8.24% interest per year compounded monthly?
361
372
@@ -365,13 +376,13 @@ def ipmt(rate, per, nper, pv, fv=0, when='end'):
365
376
financial equations start the period count at 1!
366
377
367
378
>>> per = np.arange(1*12) + 1
368
- >>> ipmt = np .ipmt(0.0824/12, per, 1*12, principal)
369
- >>> ppmt = np .ppmt(0.0824/12, per, 1*12, principal)
379
+ >>> ipmt = nf .ipmt(0.0824/12, per, 1*12, principal)
380
+ >>> ppmt = nf .ppmt(0.0824/12, per, 1*12, principal)
370
381
371
382
Each element of the sum of the 'ipmt' and 'ppmt' arrays should equal
372
383
'pmt'.
373
384
374
- >>> pmt = np .pmt(0.0824/12, 1*12, principal)
385
+ >>> pmt = nf .pmt(0.0824/12, 1*12, principal)
375
386
>>> np.allclose(ipmt + ppmt, pmt)
376
387
True
377
388
@@ -521,12 +532,15 @@ def pv(rate, nper, pmt, fv=0, when='end'):
521
532
522
533
Examples
523
534
--------
535
+ >>> import numpy as np
536
+ >>> import numpy_financial as nf
537
+
524
538
What is the present value (e.g., the initial investment)
525
539
of an investment that needs to total $15692.93
526
540
after 10 years of saving $100 every month? Assume the
527
541
interest rate is 5% (annually) compounded monthly.
528
542
529
- >>> np .pv(0.05/12, 10*12, -100, 15692.93)
543
+ >>> nf .pv(0.05/12, 10*12, -100, 15692.93)
530
544
-100.00067131625819
531
545
532
546
By convention, the negative sign represents cash flow out
@@ -538,7 +552,7 @@ def pv(rate, nper, pmt, fv=0, when='end'):
538
552
Let's compare different interest rates in the example above:
539
553
540
554
>>> a = np.array((0.05, 0.04, 0.03))/12
541
- >>> np .pv(a, 10*12, -100, 15692.93)
555
+ >>> nf .pv(a, 10*12, -100, 15692.93)
542
556
array([ -100.00067132, -649.26771385, -1273.78633713]) # may vary
543
557
544
558
So, to end up with the same $15692.93 under the same $100 per month
@@ -704,15 +718,17 @@ def irr(values):
704
718
705
719
Examples
706
720
--------
707
- >>> round(np.irr([-100, 39, 59, 55, 20]), 5)
721
+ >>> import numpy_financial as nf
722
+
723
+ >>> round(nf.irr([-100, 39, 59, 55, 20]), 5)
708
724
0.28095
709
- >>> round(np .irr([-100, 0, 0, 74]), 5)
725
+ >>> round(nf .irr([-100, 0, 0, 74]), 5)
710
726
-0.0955
711
- >>> round(np .irr([-100, 100, 0, -7]), 5)
727
+ >>> round(nf .irr([-100, 100, 0, -7]), 5)
712
728
-0.0833
713
- >>> round(np .irr([-100, 100, 0, 7]), 5)
729
+ >>> round(nf .irr([-100, 100, 0, 7]), 5)
714
730
0.06206
715
- >>> round(np .irr([-5, 10.5, 1, -8, 1]), 5)
731
+ >>> round(nf .irr([-5, 10.5, 1, -8, 1]), 5)
716
732
0.0886
717
733
718
734
"""
@@ -783,13 +799,16 @@ def npv(rate, values):
783
799
784
800
Examples
785
801
--------
802
+ >>> import numpy as np
803
+ >>> import numpy_financial as nf
804
+
786
805
Consider a potential project with an initial investment of $40 000 and
787
806
projected cashflows of $5 000, $8 000, $12 000 and $30 000 at the end of
788
807
each period discounted at a rate of 8% per period. To find the project's
789
808
net present value:
790
809
791
810
>>> rate, cashflows = 0.08, [-40_000, 5_000, 8_000, 12_000, 30_000]
792
- >>> np .npv(rate, cashflows).round(5)
811
+ >>> nf .npv(rate, cashflows).round(5)
793
812
3065.22267
794
813
795
814
It may be preferable to split the projected cashflow into an initial
@@ -799,7 +818,7 @@ def npv(rate, values):
799
818
800
819
>>> initial_cashflow = cashflows[0]
801
820
>>> cashflows[0] = 0
802
- >>> np.round(np .npv(rate, cashflows) + initial_cashflow, 5)
821
+ >>> np.round(nf .npv(rate, cashflows) + initial_cashflow, 5)
803
822
3065.22267
804
823
805
824
"""
0 commit comments