def test_xirr(): assert ff.xirr([-100, 20, 40, 25], [ date(2016, 1, 1), date(2016, 4, 1), date(2016, 10, 1), date(2017, 2, 1) ]) == -0.19674386129832788 assert ff.xirr([-100, 20, 40, 25, 8, 15], [ date(2016, 1, 1), date(2016, 4, 1), date(2016, 10, 1), date(2017, 2, 1), date(2017, 3, 1), date(2017, 6, 1) ]) == 0.0944390744445201 assert ff.xirr([-1000, 300, 400, 400, 300], [ date(2011, 12, 1), date(2012, 1, 1), date(2013, 2, 1), date(2014, 3, 1), date(2015, 4, 1) ], 0.1) == 0.23860325587217
def test_xirr_dates_not_chronological_order(): with pytest.raises(ValueError): ff.xirr([-100, 20], [date(2016, 4, 1), date(2016, 1, 1)])
def test_xirr_mismatched_lists(): with pytest.raises(ValueError): ff.xirr([-100], [])