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

Rework functions to use ufuncs? #23

Open
person142 opened this issue Oct 29, 2019 · 7 comments
Open

Rework functions to use ufuncs? #23

person142 opened this issue Oct 29, 2019 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested
Milestone

Comments

@person142
Copy link
Member

The implementation of e.g. nper:

https://github.com/numpy/numpy-financial/blob/master/numpy_financial/_financial.py#L229

requires the usual “split the array up using boolean indexes and then do different things to each hunk” stuff that you have to do when writing a function with conditional logic that operates on an entire array. This tends to lead to convoluted, hard-to-maintain code. (And nper still has more edge cases that need to be handled, so there will need to be more boolean arrays!)

One solution to this problem is to write ufuncs so that you can work with scalars and just use conditional logic. The numpy_financial functions can’t be full ufuncs because they have default arguments, but most of them can be very thin wrappers around a ufunc.

The disadvantage of introducing ufuncs is that you introduce compiled code, but perhaps it is worth it? Code for generating the loops from scalar kernels can be grabbed from SciPy (though it can be stripped down for numpy_financial since less languages need to be supported).

@Kai-Striega
Copy link
Member

This could be a good idea. The exiting split/index implementations does become convoluted especially, as you have already said, for functions with multiple edge cases. I'm not familiar enough with the low level details behind ufuncs to talk about the pros and cons in depth.

Regarding the compiled code, as we won't really need the performance benefits, is it simpler to user frompyufunc for the underlying functions?

@WarrenWeckesser thoughts?

@Kai-Striega
Copy link
Member

@charris could I ask for your opinion on this?

Personally, I agree with @person142 that the current approach (“split the array up using Boolean indexes and then do different things to each hunk”) isn't great and could be improved by using ufuncs. However, I haven't worked with the C side of ufuncs enough to be able to discuss the pro/cons in depth.

@person142
Copy link
Member Author

I guess lurking in the background there's also a bigger question of "what is the future of numpy_financial?" If the answer is "the package will be these 10 functions forever" then maybe the extra effort isn't warranted. If there are more ambitious goals in mind then you're going to want compiled code at some point anyway...

@Kai-Striega
Copy link
Member

With regard to the scope, ideally we'd be able to determine what the people actually using the financial functions will actually use. Even if we were to add more functions, with no-one to use them, the extra effort wouldn't be warranted regardless. There were some rejected PRs (e.g. np-11058 or gh-9414) so at least some demand for extensions exist.

If we do choose to expand I think the demand for "full" libraries is already filled (e.g. QuantLib). I like the scope of a financial calculator as proposed by Travis in the original discussion.

NumPy already contains functions that make it equivalent to a basic scientific calculator, should it not also contain the functions that make it equivalent to the same calculator when placed in "financial" mode? -- Travis O.

That would also include dealing with dates and many of the intricacies of the financial industry - which I don't have the expertise to maintain, or could reasonably expect someone else to have. @joelowj and @duncangh you've both been involved with numpy's financial functions, do you have any input on the future scope?

@joelowj
Copy link

joelowj commented Nov 24, 2019

@Kai-Striega, you're right. I agree with you that even if we add more functions, it will hardly get any traction as there are plenty of libraries out there that have filled the gap.

@duncangh
Copy link

duncangh commented Nov 25, 2019 via email

@joelowj
Copy link

joelowj commented Nov 28, 2019

@duncangh @Kai-Striega. Based on my experience in the industry, most of the fundamental stuff which mostly involved calculating ratios, cash flow and etc, are more suited to be done on Excel. At the same time, the more technical people in finance are the quants who would not be too interested in this basic financial functions.

Unless we are clear who are the people we are targeting and what exactly are this functions, I don't think it is worth pursuing.

@Kai-Striega Kai-Striega added enhancement New feature or request help wanted Extra attention is needed question Further information is requested labels Nov 11, 2023
@Kai-Striega Kai-Striega added this to the 2.0 milestone Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants