Skip to content

npf.rate() returns list of all nans where only one input PV/FV pair is problematic #48

@tylerdegroff

Description

@tylerdegroff

Hello,

Today I noticed that where a list of present values and a list of future values are used as input to npf.rate(), each element in the list returned is nan if only just one present/future value combination exhibits the same sign. Is this behavior intentional? I would have expected only that particular problematic pair to have returned nan, as the other pairs' results remain valid and calculable.

As you can see by the reproducible example below, all you need to do to resolve this case is drop the last element from each list and the preceding elements (all of which exhibit opposing signs) calculate as expected. Leave the last elements in place, and you get back a list of all nan.

Thanks!
-Tyler

import numpy_financial as npf

pv = [-593.06, -4725.38, -662.05, -428.78, -13.65]
fv = [214.07, 4509.97, 224.11, 686.29, -329.67]

print(npf.rate(2, 0, pv, fv))

[nan nan nan nan nan]

print(npf.rate(2, 0, pv[0:-1], fv[0:-1]))

[-0.39920185 -0.02305873 -0.41818459 0.26513414]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions