Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipmt() and ppmt() do not accept an array as per #21

Closed
Peque opened this issue Nov 18, 2021 · 4 comments · Fixed by #36
Closed

ipmt() and ppmt() do not accept an array as per #21

Peque opened this issue Nov 18, 2021 · 4 comments · Fixed by #36

Comments

@Peque
Copy link

Peque commented Nov 18, 2021

It seems that is fine with numpy_financial:

>>> numpy_financial.ipmt(rate=0.03 / 12, per=numpy.arange(35) + 1, nper=35, pv=10000)
array([-25.        , -24.3156167 , -23.62952244, -22.94171294, ...

However, with pyxirr:

>>> pyxirr.ipmt(rate=0.03 / 12, per=numpy.arange(35) + 1, nper=35, pv=10000)
TypeError: argument 'per': only size-1 arrays can be converted to Python scalars

Not sure if it is related or not, but the returned type when not using an array is also different:

>>> numpy_financial.ipmt(rate=0.03 / 12, per=1, nper=35, pv=10000)
array(-25.)                                                                    
>>> pyxirr.ipmt(rate=0.03 / 12, per=1, nper=35, pv=10000)                          
-25
@Peque
Copy link
Author

Peque commented Nov 18, 2021

It seems the same applies to pyxirr.ppmt. Updating title. 😊

@Peque Peque changed the title ipmt() does not accept an array as per ipmt()/ppmt() do not accept an array as per Nov 18, 2021
@Peque Peque changed the title ipmt()/ppmt() do not accept an array as per ipmt() / ppmt() do not accept an array as per Nov 18, 2021
@Peque Peque changed the title ipmt() / ppmt() do not accept an array as per ipmt() and ppmt() do not accept an array as per Nov 18, 2021
@Anexen
Copy link
Owner

Anexen commented Nov 18, 2021

@Peque , the same applies to all functions :)
At the moment, pyxirr doesn't support vectorized calculations. I have it in the roadmap, but I don't have any estimates.
Despite the fact that pyxirr implements all the functions from numpy_financial, it does not position itself as a drop-in-replacement for numpy_financial.

You can easily bypass this limitation by using "numpy.vectorize":

>>> ipmt = numpy.vectorize(pyxirr.ipmt)
>>> ipmt(rate=0.03 / 12, per=numpy.arange(35) + 1, nper=35, pv=10000)
array([-25.        , -24.3156167  ....

However, numpy.vectorize is likely to run slower than list comprehension:

>>> [pyxirr.ipmt(rate=0.03 / 12, per=per + 1, nper=35, pv=10000) for per in range(35)]

@Peque
Copy link
Author

Peque commented Nov 18, 2021

@Anexen Thanks for the clarification! 😊

@Anexen Anexen mentioned this issue Feb 26, 2023
@Anexen
Copy link
Owner

Anexen commented Feb 26, 2023

I finally managed to get this to work! I think I have developed an approach and will add vectorized versions of functions in the foreseeable future (probably by the end of March).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants