-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
ENH: NPV: Support calculation for vectors of rates and cashflows #96
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was taking too long and needs to be reduced
This commit introduces a native hot path using numba. This leads to an ~50x speed up on the `time_broadcast` benchmark with 100x100x100 dimension
This leads to the following improvements on the `time_broadcast` benchmark with dimension 100x100x100: * raw Python: 197 ms * numba only: 4.08 ms * numba + prange 0.3 ms
The newest released numba version is 0.58.1. This version does not support Python 3.12. Since we are using it we also cannot support Python 3.12. This should be added once numba version 0.59 is released.
Kai-Striega
added
enhancement
New feature or request
bench
Related to benchmarking numpy-financial
labels
Dec 9, 2023
These were originally added when the code was written as one function without numba. As numba is now being used, and the functions are therefore seperated. This is no longer required and makes the code more complex.
This fixes a bug where we weren't creating decimal arrays in the benchmark. Instead of creating an array and setting the dtype we manually make a list of Decimals and create an array from that list.
Kai-Striega
commented
Dec 9, 2023
@@ -8,7 +8,7 @@ jobs: | |||
strategy: | |||
matrix: | |||
os: [ubuntu-latest, macos-latest, windows-latest] | |||
python-version: ["3.9", "3.10", "3.11", "3.12"] | |||
python-version: ["3.9", "3.10", "3.11"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are required to drop Python 3.12 as Numba 0.58 doesn't support it yet. Python 3.12 should be supported in the next release. This should be released in early 2024.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NumPy-Financial now supports calculation of NPV for vectors of rates and cashflows e.g.
This was previously not supported. This behaviour was first implemented by naively looping through rates and values. As Python for loops are slow, numba is applied to accelerate the process. This has lead to a significant speedup, especially for native types.
There are some potential drawbacks to using numba:
Decimal
support