Run the test suite
mainspin test command.spin testrepository·main·Indexed 19 days ago
https://github.com/numpy/numpy-financialA standalone package providing elementary financial functions, serving as the official replacement for deprecated financial functions previously included in the main NumPy library. It includes a suite of tools for common financial calculations such as fv, ipmt, irr, mirr, nper, npv, pmt, ppmt, pv, and rate.
spin test command.spin testThe numpy-financial package provides a collection of elementary financial functions. It is the official replacement for the deprecated financial functions previously included in the main NumPy library (as per NEP-32).
To use the package, import it using the name numpy_financial. It is highly recommended to use the alias npf for brevity and convention.
import numpy_financial as npf
# Example: Calculate the Internal Rate of Return (IRR)
irr_value = npf.irr([-250000, 100000, 150000, 200000, 250000, 300000])
print(irr_value)
# Output: 0.5672303344358536numpy-financial uses a combination of Python and Cython, a build step is required. Use the spin build command to compile and build the project.spin buildWhen developing, you can use specific asv flags to get rapid feedback without the overhead of full environment builds or long execution times.
Use the following command for a fast, non-persistent run:
asv --python=same --quick --dry-runFlag breakdown:
--python=same: Uses your current development environment instead of building new ones, saving significant time.--quick: Runs each benchmark only once.--dry-run: Prevents the results from being saved to the database.Note: These flags are intended for rough development feedback and should not be used for official performance verification.
The numpy-financial package is a collection of elementary financial functions designed to replace the deprecated financial functions in the main NumPy library.
The importable name is numpy_financial. It is highly recommended to use the alias npf for brevity and standard practice.
import numpy_financial as npfOnce you have fetched the pull request and created a local branch, use git switch to move to that branch to begin editing.
git switch <BRANCH_NAME>To view benchmark results in a local web browser, you must first publish the results and then launch the preview. Follow these two steps:
asv publishasv previewasv publish
asv previewnumpy-financial are managed using asv. To execute the full benchmark suite, run the asv run command in your terminal.asv runTo get a local copy of the source code, first create a fork on GitHub at https://github.com/numpy/numpy-financial. Then, clone your personal fork to your local machine using the following command, replacing <your_username> with your actual GitHub username.
git clone https://github.com/<your_username>/numpy-financial.gitTo pull down the latest changes from the official NumPy-Financial repository into your local environment, perform a fetch followed by a fast-forward merge. This approach avoids creating unnecessary merge commits.
git fetchgit merge --ff-onlygit fetch
git merge --ff-onlyCreate a dedicated virtual environment for numpy-financial development by using the provided environment.yml file. This resolves and installs the necessary dependencies. Once created, activate the environment to begin working.
conda env create -f environment.yml
conda activate numpy-financial-devTo build the NumPy-Financial documentation, use the spin tool. This process generates the documentation as an HTML document located in the doc/build directory.
poetry must be set up.conda and spin must be installed on your system.You can verify your installations with:
conda -V
spin -Vspin docs -j 1