numpy-financial Documentation

repository·main·Indexed 19 days ago

https://github.com/numpy/numpy-financial

A 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.

Tokens
5.2K
Snippets
33
Records
36
Agent score
60%

What's inside numpy-financial

  1. Install and use numpy-financial

    main

    The 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.5672303344358536
  2. Perform quick dry runs for development feedback

    main

    When 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-run

    Flag 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.

  3. Install and import numpy-financial

    main

    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 npf
  4. Clone the NumPy-Financial repository

    main

    To 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.git
  5. Update local code with latest upstream changes

    main

    To 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.

    1. Download commits and files from the remote:
    git fetch
    1. Merge the changes using fast-forward only:
    git merge --ff-only
    git fetch
    git merge --ff-only
  6. Build the documentation using spin

    main

    To build the NumPy-Financial documentation, use the spin tool. This process generates the documentation as an HTML document located in the doc/build directory.

    Prerequisites

    • poetry must be set up.
    • A virtual environment must be active.
    • conda and spin must be installed on your system.

    You can verify your installations with:

    conda -V
    spin -V
    spin docs -j 1