@@ -234,39 +234,51 @@ def test_pmt_decimal_broadcast(self):
234
234
235
235
236
236
class TestMirr :
237
- def test_mirr (self ):
238
- val = [- 4500 , - 800 , 800 , 800 , 600 , 600 , 800 , 800 , 700 , 3000 ]
239
- assert_almost_equal (npf .mirr (val , 0.08 , 0.055 ), 0.0666 , 4 )
240
-
241
- val = [- 120000 , 39000 , 30000 , 21000 , 37000 , 46000 ]
242
- assert_almost_equal (npf .mirr (val , 0.10 , 0.12 ), 0.126094 , 6 )
237
+ @pytest .mark .parametrize ("values,finance_rate,reinvest_rate,expected" , [
238
+ ([- 4500 , - 800 , 800 , 800 , 600 , 600 , 800 , 800 , 700 , 3000 ], 0.08 , 0.055 , 0.0666 ),
239
+ ([- 120000 , 39000 , 30000 , 21000 , 37000 , 46000 ], 0.10 , 0.12 , 0.126094 ),
240
+ ([100 , 200 , - 50 , 300 , - 200 ], 0.05 , 0.06 , 0.3428 ),
241
+ ([39000 , 30000 , 21000 , 37000 , 46000 ], 0.10 , 0.12 , None )
242
+ ])
243
+ def test_mirr (self , values , finance_rate , reinvest_rate , expected ):
244
+ result = npf .mirr (values , finance_rate , reinvest_rate )
243
245
244
- val = [100 , 200 , - 50 , 300 , - 200 ]
245
- assert_almost_equal (npf .mirr (val , 0.05 , 0.06 ), 0.3428 , 4 )
246
+ if expected :
247
+ decimal_part_len = len (str (expected ).split ('.' )[1 ])
248
+ assert_almost_equal (result , expected , decimal_part_len )
249
+ else :
250
+ assert_ (numpy .isnan (result ))
246
251
247
- val = [39000 , 30000 , 21000 , 37000 , 46000 ]
248
- assert_ (numpy .isnan (npf .mirr (val , 0.10 , 0.12 )))
249
-
250
- def test_mirr_decimal (self ):
251
- val = [Decimal ('-4500' ), Decimal ('-800' ), Decimal ('800' ),
252
- Decimal ('800' ), Decimal ('600' ), Decimal ('600' ), Decimal ('800' ),
253
- Decimal ('800' ), Decimal ('700' ), Decimal ('3000' )]
254
- assert_equal (npf .mirr (val , Decimal ('0.08' ), Decimal ('0.055' )),
255
- Decimal ('0.066597175031553548874239618' ))
256
-
257
- val = [Decimal ('-120000' ), Decimal ('39000' ), Decimal ('30000' ),
258
- Decimal ('21000' ), Decimal ('37000' ), Decimal ('46000' )]
259
- assert_equal (npf .mirr (val , Decimal ('0.10' ), Decimal ('0.12' )),
260
- Decimal ('0.126094130365905145828421880' ))
261
-
262
- val = [Decimal ('100' ), Decimal ('200' ), Decimal ('-50' ),
263
- Decimal ('300' ), Decimal ('-200' )]
264
- assert_equal (npf .mirr (val , Decimal ('0.05' ), Decimal ('0.06' )),
265
- Decimal ('0.342823387842176663647819868' ))
266
-
267
- val = [Decimal ('39000' ), Decimal ('30000' ), Decimal ('21000' ),
268
- Decimal ('37000' ), Decimal ('46000' )]
269
- assert_ (numpy .isnan (npf .mirr (val , Decimal ('0.10' ), Decimal ('0.12' ))))
252
+ @pytest .mark .parametrize ('number_type' , [Decimal , float ])
253
+ @pytest .mark .parametrize (
254
+ "args, expected" ,
255
+ [
256
+ ({'values' : ['-4500' , '-800' , '800' , '800' , '600' , '600' , '800' , '800' , '700' , '3000' ],
257
+ 'finance_rate' : '0.08' , 'reinvest_rate' : '0.055'
258
+ }, '0.066597175031553548874239618'
259
+ ),
260
+ ({'values' : ['-120000' , '39000' , '30000' , '21000' , '37000' , '46000' ],
261
+ 'finance_rate' : '0.10' , 'reinvest_rate' : '0.12'
262
+ }, '0.126094130365905145828421880'
263
+ ),
264
+ ({'values' : ['100' , '200' , '-50' , '300' , '-200' ],
265
+ 'finance_rate' : '0.05' , 'reinvest_rate' : '0.06'
266
+ }, '0.342823387842176663647819868'
267
+ ),
268
+ ({'values' : ['39000' , '30000' , '21000' , '37000' , '46000' ],
269
+ 'finance_rate' : '0.10' , 'reinvest_rate' : '0.12'
270
+ }, numpy .nan
271
+ ),
272
+ ],
273
+ )
274
+ def test_mirr_decimal (self , number_type , args , expected ):
275
+ values = [number_type (v ) for v in args ['values' ]]
276
+ result = npf .mirr (values , number_type (args ['finance_rate' ]), number_type (args ['reinvest_rate' ]))
277
+
278
+ if expected is not numpy .nan :
279
+ assert_almost_equal (result , number_type (expected ), 15 )
280
+ else :
281
+ assert numpy .isnan (result )
270
282
271
283
def test_mirr_no_real_solution_exception (self ):
272
284
# Test that if there is no solution because all the cashflows
0 commit comments