### Install numpy-financial Source: https://numpy.org/numpy-financial Install the numpy-financial package using pip. This is the first step to using the financial functions. ```bash $ pip install numpy-financial ``` -------------------------------- ### Calculate NPV with Initial Investment Source: https://numpy.org/numpy-financial/latest/npv.html Calculates the Net Present Value (NPV) of a project with an initial investment and subsequent cash flows. The cash flows are provided as a list, starting with the initial investment (typically negative). ```python rate, cashflows = 0.08, [-40_000, 5_000, 8_000, 12_000, 30_000] npf.npv(rate, cashflows).round(5) ``` -------------------------------- ### Calculate Monthly Loan Payment Source: https://numpy.org/numpy-financial/latest/pmt.html Calculate the monthly payment required to pay off a loan. This example demonstrates a common use case for the pmt function with default future value. ```python >>> npf.pmt(0.075/12, 12*15, 200000) -1854.0247200054619 ``` -------------------------------- ### numpy_financial.npv Source: https://numpy.org/numpy-financial/latest/npv.html Returns the NPV (Net Present Value) of a cash flow series. It considers a series of cashflows starting in the present (t = 0). ```APIDOC ## numpy_financial.npv ### Description Returns the NPV (Net Present Value) of a cash flow series. The function assumes cash flows start at the present time (t=0). ### Method N/A (Python function) ### Parameters #### Arguments * **rate** (scalar) - The discount rate. * **values** (array_like, shape(M, )) - The values of the time series of cash flows. The time interval between cash flows must be consistent with the rate. Values should typically begin with a negative number representing the initial investment. ### Returns * **out** (float) - The NPV of the input cash flow series. ### Warning `npv` considers a series of cashflows starting in the present (t = 0). NPV can also be defined with a series of future cashflows, paid at the end, rather than the start, of each period. If future cashflows are used, the first cashflow values[0] must be zeroed and added to the net present value of the future cashflows. ### Examples ```python >>> import numpy as np >>> import numpy_financial as npf # Example 1: Calculating NPV with initial investment and future cashflows >>> rate, cashflows = 0.08, [-40_000, 5_000, 8_000, 12_000, 30_000] >>> npf.npv(rate, cashflows).round(5) 3065.22267 # Example 2: Handling future cashflows by adjusting the first value and adding initial investment separately >>> initial_cashflow = cashflows[0] >>> cashflows[0] = 0 >>> np.round(npf.npv(rate, cashflows) + initial_cashflow, 5) 3065.22267 ``` ``` -------------------------------- ### Import and Use numpy-financial Source: https://numpy.org/numpy-financial/latest Demonstrates how to import the numpy-financial package with the recommended alias 'npf' and use the 'irr' function to calculate the Internal Rate of Return. ```python >>> import numpy_financial as npf >>> npf.irr([-250000, 100000, 150000, 200000, 250000, 300000]) 0.5672303344358536 ``` -------------------------------- ### Calculate Amortization Schedule for a Loan Source: https://numpy.org/numpy-financial/latest/ipmt.html Demonstrates how to calculate the amortization schedule for a loan, including interest and principal payments, and the remaining principal balance. This snippet is useful for financial analysis and loan tracking. ```python >>> import numpy as np >>> import numpy_financial as npf ``` ```python >>> principal = 2500.00 ``` ```python >>> per = np.arange(1*12) + 1 >>> ipmt = npf.ipmt(0.0824/12, per, 1*12, principal) >>> ppmt = npf.ppmt(0.0824/12, per, 1*12, principal) ``` ```python >>> pmt = npf.pmt(0.0824/12, 1*12, principal) >>> np.allclose(ipmt + ppmt, pmt) True ``` ```python >>> fmt = '{0:2d} {1:8.2f} {2:8.2f} {3:8.2f}' >>> for payment in per: ... index = payment - 1 ... principal = principal + ppmt[index] ... print(fmt.format(payment, ppmt[index], ipmt[index], principal)) ``` ```python >>> interestpd = np.sum(ipmt) >>> np.round(interestpd, 2) -112.98 ``` -------------------------------- ### Import Numpy-Financial Source: https://numpy.org/numpy-financial/latest/pmt.html Import the numpy_financial library for use in subsequent calculations. ```python import numpy_financial as npf ``` -------------------------------- ### Import Numpy and Numpy-Financial Source: https://numpy.org/numpy-financial/latest/npv.html Imports the necessary libraries for numerical operations and financial calculations. ```python import numpy as np import numpy_financial as npf ``` -------------------------------- ### Calculate Present Value with Specific Inputs Source: https://numpy.org/numpy-financial/latest/pv.html Calculates the initial investment needed to reach a future value with regular monthly savings and a given interest rate. The negative sign indicates cash outflow. ```python >>> import numpy as np >>> import numpy_financial as npf >>> npf.pv(0.05/12, 10*12, -100, 15692.93) -100.00067131625819 ``` -------------------------------- ### Compare Present Value Across Different Interest Rates Source: https://numpy.org/numpy-financial/latest/pv.html Compares the present value required to reach a target future value with the same monthly savings plan but varying interest rates. Demonstrates handling of array-like inputs for the rate. ```python >>> a = np.array((0.05, 0.04, 0.03))/12 >>> npf.pv(a, 10*12, -100, 15692.93) array([ -100.00067132, -649.26771385, -1273.78633713]) # may vary ``` -------------------------------- ### Batch calculation of loan payoff time Source: https://numpy.org/numpy-financial/latest/nper.html Perform calculations for multiple scenarios of interest rates, payments, and loan amounts simultaneously to generate a table of results. This uses numpy's ogrid for creating arrays of values. ```python print(npf.nper(*(np.ogrid[0.07/12: 0.08/12: 0.01/12, -150 : -99 : 50 , 8000 : 9001 : 1000]))) ``` -------------------------------- ### pmt Source: https://numpy.org/numpy-financial/latest/index.html Compute the payment against loan principal plus interest. ```APIDOC ## pmt ### Description Compute the payment against loan principal plus interest. ### Parameters * **rate** (float) - The periodic interest rate. * **nper** (int) - The total number of payment periods. * **pv** (float) - The present value. * **fv** (float, optional) - The future value. Defaults to 0. * **when** (str, optional) - When payments are due. Defaults to 'end'. * 'end' - End of the period * 'begin' - Beginning of the period ``` -------------------------------- ### Calculate Future Value with Array-like Inputs Source: https://numpy.org/numpy-financial/latest/fv.html Compute the future value for multiple interest rates simultaneously. Returns an array of future values corresponding to each input rate. ```python a = np.array((0.05, 0.06, 0.07))/12 npf.fv(a, 10*12, -100, -100) ``` -------------------------------- ### ppmt Source: https://numpy.org/numpy-financial/latest/index.html Compute the payment against loan principal. ```APIDOC ## ppmt ### Description Compute the payment against loan principal. ### Parameters * **rate** (float) - The periodic interest rate. * **per** (int) - The period for which the principal payment is calculated. * **nper** (int) - The total number of payment periods. * **pv** (float) - The present value. * **fv** (float, optional) - The future value. Defaults to 0. * **when** (str, optional) - When payments are due. Defaults to 'end'. * 'end' - End of the period * 'begin' - Beginning of the period ``` -------------------------------- ### pv Source: https://numpy.org/numpy-financial/latest/index.html Compute the present value. ```APIDOC ## pv ### Description Compute the present value. ### Parameters * **rate** (float) - The periodic interest rate. * **nper** (int) - The total number of payment periods. * **pmt** (float) - The payment made each period. * **fv** (float, optional) - The future value. Defaults to 0. * **when** (str, optional) - When payments are due. Defaults to 'end'. * 'end' - End of the period * 'begin' - Beginning of the period ``` -------------------------------- ### rate Source: https://numpy.org/numpy-financial/latest Compute the interest rate per period for a loan or investment, given the number of periods, payment amount, present value, and future value. ```APIDOC ## rate ### Description Compute the rate of interest per period. ### Signature rate(nper, pmt, pv, fv[, when, guess, tol, maxiter, method]) ### Parameters * **nper** : float or array_like of floats The total number of payment periods. * **pmt** : float or array_like of floats The payment made each period. * **pv** : float or array_like of floats The present value. * **fv** : float or array_like of floats, optional The future value, or amount that a series of future payments is worth, including an optional last payment, which is only made at the end of the nth period. Should be zero if omitted. * **when** : {{'begin', 'end'}}, string, int, or float, optional When payments are due. Defaults to 'end'. * **guess** : float or None, optional The starting guess for the rate. * **tol** : float, optional The tolerance for convergence. * **maxiter** : int, optional The maximum number of iterations to perform. * **method** : {{'newton'}}, string, optional The method to use for solving. ### Returns * **rate** : float or ndarray of floats The rate of interest per period. ### Example ```python >>> import numpy_financial as npf >>> npf.rate(10, -100, -1000, 1628.8946267774414) 0.050000000000000044 ``` ``` -------------------------------- ### numpy_financial.pmt Source: https://numpy.org/numpy-financial/latest/pmt.html Computes the periodic payment for a loan or investment, solving for 'pmt' in the given financial equation. ```APIDOC ## numpy_financial.pmt ### Description Compute the payment against loan principal plus interest. ### Method `numpy_financial.pmt` ### Parameters #### Arguments * **rate** (array_like) - Rate of interest (per period) * **nper** (array_like) - Number of compounding periods * **pv** (array_like) - Present value * **fv** (array_like, optional) - Future value (default = 0) * **when** ({{‘begin’, 1}, {‘end’, 0}}, {string, int}, optional) - When payments are due (‘begin’ (1) or ‘end’ (0)) (default = 'end') ### Returns * **out** (ndarray) - Payment against loan plus interest. If all input is scalar, returns a scalar float. If any input is array_like, returns payment for each input element. If multiple inputs are array_like, they all must have the same shape. ### Notes The payment is computed by solving the equation: ``` fv + pv*(1 + rate)**nper + pmt*(1 + rate*when)/rate*((1 + rate)**nper - 1) == 0 ``` or, when `rate == 0`: ``` fv + pv + pmt * nper == 0 ``` for `pmt`. ### Examples ```python >>> import numpy_financial as npf # What is the monthly payment needed to pay off a $200,000 loan in 15 years at an annual interest rate of 7.5%? >>> npf.pmt(0.075/12, 12*15, 200000) -1854.0247200054619 ``` In order to pay-off (i.e., have a future-value of 0) the $200,000 obtained today, a monthly payment of $1,854.02 would be required. Note that this example illustrates usage of fv having a default value of 0. ``` -------------------------------- ### Calculate Internal Rate of Return (IRR) Source: https://numpy.org/numpy-financial Use the numpy_financial package with the alias 'npf' to calculate the internal rate of return for a series of cash flows. Ensure the package is imported correctly. ```python >>> import numpy_financial as npf >>> npf.irr([-250000, 100000, 150000, 200000, 250000, 300000]) 0.5672303344358536 ``` -------------------------------- ### Calculate NPV for Future Cash Flows Source: https://numpy.org/numpy-financial/latest/npv.html Calculates the Net Present Value (NPV) by separating the initial investment from future cash flows. The initial cash flow is set to zero, and the initial investment is added to the NPV of the future cash flows. This method is useful when cash flows are defined as occurring at the end of each period. ```python initial_cashflow = cashflows[0] cashflows[0] = 0 np.round(npf.npv(rate, cashflows) + initial_cashflow, 5) ``` -------------------------------- ### fv Source: https://numpy.org/numpy-financial/latest/index.html Compute the future value. ```APIDOC ## fv ### Description Compute the future value. ### Parameters * **rate** (float) - The periodic interest rate. * **nper** (int) - The total number of payment periods. * **pmt** (float) - The payment made each period. * **pv** (float) - The present value. * **when** (str, optional) - When payments are due. Defaults to 'end'. * 'end' - End of the period * 'begin' - Beginning of the period ``` -------------------------------- ### rate Source: https://numpy.org/numpy-financial/latest/index.html Compute the rate of interest per period. ```APIDOC ## rate ### Description Compute the rate of interest per period. ### Parameters * **nper** (int) - The total number of payment periods. * **pmt** (float) - The payment made each period. * **pv** (float) - The present value. * **fv** (float, optional) - The future value. Defaults to 0. * **when** (str, optional) - When payments are due. Defaults to 'end'. * 'end' - End of the period * 'begin' - Beginning of the period * **guess** (float, optional) - The guessed rate of interest per period. Defaults to None. * **tol** (float, optional) - The tolerance for the solution. Defaults to None. * **maxiter** (int, optional) - The maximum number of iterations. Defaults to None. ``` -------------------------------- ### ppmt Source: https://numpy.org/numpy-financial/latest Compute the payment against loan principal for a loan based on a constant interest rate and periodic payments. ```APIDOC ## ppmt ### Description Compute the payment against loan principal. ### Signature ppmt(rate, per, nper, pv[, fv, when]) ### Parameters * **rate** : float or array_like of floats Rate of interest per period. * **per** : float or array_like of floats The period for which the principal is paid. * **nper** : float or array_like of floats The total number of payment periods. * **pv** : float or array_like of floats The present value. * **fv** : float or array_like of floats, optional The future value, or amount that a series of future payments is worth, including an optional last payment, which is only made at the end of the nth period. Should be zero if omitted. * **when** : {{'begin', 'end'}}, string, int, or float, optional When payments are due. Defaults to 'end'. ### Returns * **ppmt** : float or ndarray of floats Principal portion of the payment for the specified period. ### Example ```python >>> import numpy_financial as npf >>> npf.ppmt(0.05, 3, 10, -1000) -114.46312563661157 ``` ``` -------------------------------- ### Calculate Future Value with Scalar Inputs Source: https://numpy.org/numpy-financial/latest/fv.html Compute the future value for a single set of investment parameters. The negative sign indicates cash outflow. ```python npf.fv(0.05/12, 10*12, -100, -100) ``` -------------------------------- ### Compute Rate of Interest Source: https://numpy.org/numpy-financial/latest/rate.html Use this function to compute the rate of interest per period. The equation is solved iteratively for 'rate'. ```python fv + pv*(1+rate)**nper + pmt*(1+rate*when)/rate * ((1+rate)**nper - 1) = 0 ``` -------------------------------- ### Calculate IRR for a series of cash flows Source: https://numpy.org/numpy-financial/latest/irr.html Calculates the Internal Rate of Return (IRR) for a given set of cash flows. The first element of the values array typically represents the initial investment (negative). ```python import numpy_financial as npf ``` ```python round(npf.irr([-100, 39, 59, 55, 20]), 5) 0.28095 ``` ```python round(npf.irr([-100, 0, 0, 74]), 5) -0.0955 ``` ```python round(npf.irr([-100, 100, 0, -7]), 5) -0.0833 ``` ```python round(npf.irr([-100, 100, 0, 7]), 5) 0.06206 ``` ```python round(npf.irr([-5, 10.5, 1, -8, 1]), 5) 0.0886 ``` -------------------------------- ### npv Source: https://numpy.org/numpy-financial/latest Calculate the Net Present Value (NPV) of a series of cash flows, discounted at a specified rate. ```APIDOC ## npv ### Description Returns the NPV (Net Present Value) of a cash flow series. ### Signature npv(rate, values) ### Parameters * **rate** : float or array_like of floats Rate of interest per period. * **values** : array_like, float Monthly cash flow series, as length is not required. ### Returns * **npv** : float or ndarray of floats The NPV of the values. ### Example ```python >>> import numpy_financial as npf >>> npf.npv(0.05, [-1000000, 100000, 150000, 200000, 250000, 300000]) -155.041149610176187 ``` ``` -------------------------------- ### pmt Source: https://numpy.org/numpy-financial/latest Compute the periodic payment required to pay off a loan or reach a future value, considering principal and interest. ```APIDOC ## pmt ### Description Compute the payment against loan principal plus interest. ### Signature pmt(rate, nper, pv[, fv, when]) ### Parameters * **rate** : float or array_like of floats Rate of interest per period. * **nper** : float or array_like of floats The total number of payment periods. * **pv** : float or array_like of floats The present value. * **fv** : float or array_like of floats, optional The future value, or amount that a series of future payments is worth, including an optional last payment, which is only made at the end of the nth period. Should be zero if omitted. * **when** : {{'begin', 'end'}}, string, int, or float, optional When payments are due. Defaults to 'end'. ### Returns * **pmt** : float or ndarray of floats The payment made each period. ### Example ```python >>> import numpy_financial as npf >>> npf.pmt(0.05, 10, -1000) 129.5045756497911 ``` ``` -------------------------------- ### numpy_financial.ppmt Source: https://numpy.org/numpy-financial/latest/ppmt.html Computes the payment against loan principal. This function is useful for financial calculations involving loans and mortgages. ```APIDOC ## numpy_financial.ppmt ### Description Compute the payment against loan principal. ### Method N/A (Python function) ### Endpoint N/A (Python function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Parameters #### Function Parameters - **rate** (array_like) - Rate of interest (per period) - **per** (array_like, int) - Amount paid against the loan changes. The per is the period of interest. - **nper** (array_like) - Number of compounding periods - **pv** (array_like) - Present value - **fv** (array_like, optional) - Future value. Defaults to 0. - **when** ({‘begin’, 1}, {‘end’, 0}, string, int) - When payments are due (‘begin’ (1) or ‘end’ (0)). Defaults to ‘end’. ### Request Example N/A (Python function) ### Response #### Success Response Returns the payment against loan principal. #### Response Example N/A (Python function) ``` -------------------------------- ### numpy_financial.pv Source: https://numpy.org/numpy-financial/latest/pv.html Computes the present value given a future value, interest rate per period, number of periods, and a fixed payment amount. Payments can be made at the beginning or end of each period. ```APIDOC ## numpy_financial.pv ### Description Compute the present value of a series of payments or investments. ### Method `pv(rate, nper, pmt, fv=0, when='end')` ### Parameters #### Path Parameters - **rate** (array_like) - Rate of interest (per period) - **nper** (array_like) - Number of compounding periods - **pmt** (array_like) - Payment - **fv** (array_like, optional) - Future value. Defaults to 0. - **when** ({'begin', 1}, {'end', 0}), {string, int}, optional - When payments are due (‘begin’ (1) or ‘end’ (0)). Defaults to 'end'. ### Returns - **out** (ndarray, float) - Present value of a series of payments or investments. ### Notes The present value is computed by solving the equation: ``` fv + pv*(1 + rate)**nper + pmt*(1 + rate*when)/rate*((1 + rate)**nper - 1) = 0 ``` or, when `rate = 0`: ``` fv + pv + pmt * nper = 0 ``` for pv, which is then returned. ### Request Example ```python >>> import numpy as np >>> import numpy_financial as npf >>> npf.pv(0.05/12, 10*12, -100, 15692.93) -100.00067131625819 ``` ### Response Example ```python # Output may vary slightly based on floating point precision >>> npf.pv(0.05/12, 10*12, -100, 15692.93) -100.00067131625819 ``` ``` -------------------------------- ### fv Source: https://numpy.org/numpy-financial/latest Compute the future value of an investment based on a constant interest rate and periodic payments. ```APIDOC ## fv ### Description Compute the future value. ### Signature fv(rate, nper, pmt, pv[, when]) ### Parameters * **rate** : float or array_like of floats Rate of interest per period. * **nper** : float or array_like of floats The total number of payment periods. * **pmt** : float or array_like of floats The payment made each period. * **pv** : float or array_like of floats The present value. * **when** : {{'begin', 'end'}}, string, int, or float, optional When payments are due. Defaults to 'end'. ### Returns * **fv** : float or ndarray of floats Future value of the investment. ### Example ```python >>> import numpy_financial as npf >>> npf.fv(0.05, 5, -100, -1000) 1628.8946267774414 ``` ``` -------------------------------- ### pv Source: https://numpy.org/numpy-financial/latest Compute the present value of an investment or loan based on a constant interest rate and periodic payments. ```APIDOC ## pv ### Description Compute the present value. ### Signature pv(rate, nper, pmt[, fv, when]) ### Parameters * **rate** : float or array_like of floats Rate of interest per period. * **nper** : float or array_like of floats The total number of payment periods. * **pmt** : float or array_like of floats The payment made each period. * **fv** : float or array_like of floats, optional The future value, or amount that a series of future payments is worth, including an optional last payment, which is only made at the end of the nth period. Should be zero if omitted. * **when** : {{'begin', 'end'}}, string, int, or float, optional When payments are due. Defaults to 'end'. ### Returns * **pv** : float or ndarray of floats The present value. ### Example ```python >>> import numpy_financial as npf >>> npf.pv(0.05, 5, -100, 1628.8946267774414) -1000.0000000000002 ``` ``` -------------------------------- ### Calculate loan payoff time Source: https://numpy.org/numpy-financial/latest/nper.html Determine the number of months to pay off a loan given specific financial parameters. The result is rounded to 5 decimal places. ```python print(np.round(npf.nper(0.07/12, -150, 8000), 5)) ``` -------------------------------- ### Use numpy_financial with NumPy namespace Source: https://numpy.org/numpy-financial When using NumPy arrays, import numpy_financial as 'npf' and call financial functions using the 'npf' namespace. This approach is necessary for code that previously used NumPy's financial functions via the 'np' alias. ```python import numpy as np import numpy_financial as npf x = np.array([-250000, 100000, 150000, 200000, 250000, 300000]) r = npf.irr(x) ``` -------------------------------- ### ipmt Source: https://numpy.org/numpy-financial/latest/index.html Compute the interest portion of a payment. ```APIDOC ## ipmt ### Description Compute the interest portion of a payment. ### Parameters * **rate** (float) - The periodic interest rate. * **per** (int) - The period for which the interest is calculated. * **nper** (int) - The total number of payment periods. * **pv** (float) - The present value. * **fv** (float, optional) - The future value. Defaults to 0. * **when** (str, optional) - When payments are due. Defaults to 'end'. * 'end' - End of the period * 'begin' - Beginning of the period ``` -------------------------------- ### Import npv and irr from numpy_financial Source: https://numpy.org/numpy-financial Modify existing imports from 'numpy' to 'numpy_financial' when switching to the new package. This allows direct use of functions like 'npv' and 'irr'. ```python from numpy_financial import npv, irr ``` -------------------------------- ### irr Source: https://numpy.org/numpy-financial/latest/index.html Return the Internal Rate of Return (IRR). ```APIDOC ## irr ### Description Return the Internal Rate of Return (IRR). ### Parameters * **values** (array_like) - Cash flow values over the same period. ``` -------------------------------- ### irr Source: https://numpy.org/numpy-financial/latest Return the Internal Rate of Return (IRR) for a series of cash flows. ```APIDOC ## irr ### Description Return the Internal Rate of Return (IRR). ### Signature irr(values) ### Parameters * **values** : array_like, float Monthly cash flow series, as length is not required. ### Returns * **irr** : float Internal rate of return of the values. ### Example ```python >>> import numpy_financial as npf >>> npf.irr([-250000, 100000, 150000, 200000, 250000, 300000]) 0.5672303344358536 ``` ``` -------------------------------- ### numpy_financial.ipmt Source: https://numpy.org/numpy-financial/latest/ipmt.html Computes the interest portion of a payment for a loan. It takes the interest rate per period, the payment period, the total number of periods, the present value (loan amount), and optionally the future value and when payments are due. ```APIDOC ## numpy_financial.ipmt ### Description Compute the interest portion of a payment. ### Method `numpy_financial.ipmt(rate, per, nper, pv, fv=0, when='end')` ### Parameters #### Parameters - **rate** (scalar or array_like of shape(M, )) - Rate of interest as decimal (not per cent) per period - **per** (scalar or array_like of shape(M, )) - Interest paid against the loan changes during the life or the loan. The per is the payment period to calculate the interest amount. - **nper** (scalar or array_like of shape(M, )) - Number of compounding periods - **pv** (scalar or array_like of shape(M, )) - Present value - **fv** (scalar or array_like of shape(M, ), optional) - Future value. Defaults to 0. - **when** ({‘begin’, 1}, {‘end’, 0}, string, int}, optional) - When payments are due (‘begin’ (1) or ‘end’ (0)). Defaults to {‘end’, 0}. ### Returns #### Returns - **out** (ndarray) - Interest portion of payment. If all input is scalar, returns a scalar float. If any input is array_like, returns interest payment for each input element. If multiple inputs are array_like, they all must have the same shape. ### See also `ppmt`, `pmt`, `pv` ### Notes The total payment is made up of payment against principal plus interest. `pmt = ppmt + ipmt` ### Examples ```python >>> import numpy as np >>> import numpy_financial as npf ``` What is the amortization schedule for a 1 year loan of $2500 at 8.24% interest per year compounded monthly? ```python >>> principal = 2500.00 ``` The ‘per’ variable represents the periods of the loan. Remember that financial equations start the period count at 1! ```python >>> per = np.arange(1*12) + 1 >>> ipmt = npf.ipmt(0.0824/12, per, 1*12, principal) >>> ppmt = npf.ppmt(0.0824/12, per, 1*12, principal) ``` Each element of the sum of the ‘ipmt’ and ‘ppmt’ arrays should equal ‘pmt’. ```python >>> pmt = npf.pmt(0.0824/12, 1*12, principal) >>> np.allclose(ipmt + ppmt, pmt) True ``` ```python >>> fmt = '{0:2d} {1:8.2f} {2:8.2f} {3:8.2f}' >>> for payment in per: ... index = payment - 1 ... principal = principal + ppmt[index] ... print(fmt.format(payment, ppmt[index], ipmt[index], principal)) 1 -200.58 -17.17 2299.42 2 -201.96 -15.79 2097.46 3 -203.35 -14.40 1894.11 4 -204.74 -13.01 1689.37 5 -206.15 -11.60 1483.22 6 -207.56 -10.18 1275.66 7 -208.99 -8.76 1066.67 8 -210.42 -7.32 856.25 9 -211.87 -5.88 644.38 10 -213.32 -4.42 431.05 11 -214.79 -2.96 216.26 12 -216.26 -1.49 -0.00 ``` ```python >>> interestpd = np.sum(ipmt) >>> np.round(interestpd, 2) -112.98 ``` ``` -------------------------------- ### npv Source: https://numpy.org/numpy-financial/latest/index.html Returns the NPV (Net Present Value) of a cash flow series. ```APIDOC ## npv ### Description Returns the NPV (Net Present Value) of a cash flow series. ### Parameters * **rate** (float) - The discount rate for the cash flow series. * **values** (array_like) - The series of cash flows. ``` -------------------------------- ### numpy_financial.rate Source: https://numpy.org/numpy-financial/latest/rate.html Computes the rate of interest per period. This function iteratively solves a non-linear equation to find the rate. ```APIDOC ## numpy_financial.rate ### Description Compute the rate of interest per period. ### Method Call ### Parameters #### Path Parameters - **nper** (array_like) - Number of compounding periods - **pmt** (array_like) - Payment - **pv** (array_like) - Present value - **fv** (array_like) - Future value - **when** (string, int) - Optional - When payments are due (‘begin’ (1) or ‘end’ (0)) - **guess** (Number) - Optional - Starting guess for solving the rate of interest, default 0.1 - **tol** (Number) - Optional - Required tolerance for the solution, default 1e-6 - **maxiter** (int) - Optional - Maximum iterations in finding the solution ### Notes The rate of interest is computed by iteratively solving the (non-linear) equation: ``` fv + pv*(1+rate)**nper + pmt*(1+rate*when)/rate * ((1+rate)**nper - 1) = 0 ``` for `rate`. ``` -------------------------------- ### nper Source: https://numpy.org/numpy-financial/latest/index.html Compute the number of periodic payments. ```APIDOC ## nper ### Description Compute the number of periodic payments. ### Parameters * **rate** (float) - The periodic interest rate. * **pmt** (float) - The payment made each period. * **pv** (float) - The present value. * **fv** (float, optional) - The future value. Defaults to 0. * **when** (str, optional) - When payments are due. Defaults to 'end'. * 'end' - End of the period * 'begin' - Beginning of the period ``` -------------------------------- ### numpy_financial.fv Source: https://numpy.org/numpy-financial/latest/fv.html Computes the future value of an investment. It takes into account the present value, interest rate, number of periods, and periodic payment amount. Payments can be made at the beginning or end of each period. ```APIDOC ## numpy_financial.fv ### Description Computes the future value of an investment based on periodic cash flows and a discount rate. ### Method `fv(rate, nper, pmt, pv, when='end')` ### Parameters #### Path Parameters - **rate** (scalar or array_like) - Rate of interest as decimal (not per cent) per period. - **nper** (scalar or array_like) - Number of compounding periods. - **pmt** (scalar or array_like) - Payment made each period. - **pv** (scalar or array_like) - Present value. - **when** ({‘begin’, 1}, {‘end’, 0}, string, int) - Optional. When payments are due (‘begin’ or ‘end’). Defaults to ‘end’. ### Returns - **out** (ndarray) - Future values. Returns a scalar float if all inputs are scalar, otherwise returns an ndarray of future values. ### Examples ```python >>> import numpy as np >>> import numpy_financial as npf # Calculate future value with monthly savings >>> npf.fv(0.05/12, 10*12, -100, -100) 15692.928894335748 # Compare future values with different interest rates >>> a = np.array((0.05, 0.06, 0.07))/12 >>> npf.fv(a, 10*12, -100, -100) array([ 15692.92889434, 16569.87435405, 17509.44688102]) # may vary ``` ``` -------------------------------- ### ipmt Source: https://numpy.org/numpy-financial/latest Compute the interest portion of a payment for an investment or loan based on a constant interest rate and periodic payments. ```APIDOC ## ipmt ### Description Compute the interest portion of a payment. ### Signature ipmt(rate, per, nper, pv[, fv, when]) ### Parameters * **rate** : float or array_like of floats Rate of interest per period. * **per** : float or array_like of floats The period for which the interest is calculated. * **nper** : float or array_like of floats The total number of payment periods. * **pv** : float or array_like of floats The present value. * **fv** : float or array_like of floats, optional The future value, or amount that a series of future payments is worth, including an optional last payment, which is only made at the end of the nth period. Should be zero if omitted. * **when** : {{'begin', 'end'}}, string, int, or float, optional When payments are due. Defaults to 'end'. ### Returns * **ipmt** : float or ndarray of floats Interest portion of the payment for the specified period. ### Example ```python >>> import numpy_financial as npf >>> npf.ipmt(0.05, 3, 10, -1000) -15.041149610176187 ``` ``` -------------------------------- ### nper Source: https://numpy.org/numpy-financial/latest Compute the number of periodic payments required to pay off a loan or reach a future value. ```APIDOC ## nper ### Description Compute the number of periodic payments. ### Signature nper(rate, pmt, pv[, fv, when]) ### Parameters * **rate** : float or array_like of floats Rate of interest per period. * **pmt** : float or array_like of floats The payment made each period. * **pv** : float or array_like of floats The present value. * **fv** : float or array_like of floats, optional The future value, or amount that a series of future payments is worth, including an optional last payment, which is only made at the end of the nth period. Should be zero if omitted. * **when** : {{'begin', 'end'}}, string, int, or float, optional When payments are due. Defaults to 'end'. ### Returns * **nper** : float or ndarray of floats The number of payment periods. ### Example ```python >>> import numpy_financial as npf >>> npf.nper(0.05, -100, -1000) 11.000000000000002 ``` ``` -------------------------------- ### mirr Source: https://numpy.org/numpy-financial/latest/index.html Modified internal rate of return. ```APIDOC ## mirr ### Description Modified internal rate of return. ### Parameters * **values** (array_like) - Cash flow values over the same period. * **finance_rate** (float) - The interest rate for the cash flows on hand. * **reinvest_rate** (float) - The interest rate for the cash flows that have been reinvested. ``` -------------------------------- ### numpy_financial.mirr Source: https://numpy.org/numpy-financial/latest/mirr.html Calculates the modified internal rate of return (MIRR) for a series of cash flows, considering different financing and reinvestment rates. ```APIDOC ## numpy_financial.mirr ### Description Calculates the modified internal rate of return. ### Parameters #### Positional Parameters - **values** (array_like) - Required - Cash flows (must contain at least one positive and one negative value) or nan is returned. The first value is considered a sunk cost at time zero. - **finance_rate** (scalar) - Required - Interest rate paid on the cash flows. - **reinvest_rate** (scalar) - Required - Interest rate received on the cash flows upon reinvestment. ### Returns #### out (float) Modified internal rate of return. ``` -------------------------------- ### numpy_financial.irr Source: https://numpy.org/numpy-financial/latest/irr.html Calculates the Internal Rate of Return (IRR) for a given series of cash flows. The function assumes that cash flows occur at regular intervals. Net deposits are represented as negative values, and net withdrawals as positive values. The first element typically represents the initial investment and is usually negative. ```APIDOC ## numpy_financial.irr ### Description Returns the Internal Rate of Return (IRR). This is the "average" periodically compounded rate of return that gives a net present value of 0.0. ### Method `numpy_financial.irr(values)` ### Parameters #### Path Parameters - **values** (array_like, shape(N,)) - Input cash flows per time period. By convention, net "deposits" are negative and net "withdrawals" are positive. Thus, for example, at least the first element of values, which represents the initial investment, will typically be negative. ### Returns #### Success Response - **out** (float) - Internal Rate of Return for periodic input values. ### Examples ```python >>> import numpy_financial as npf >>> round(npf.irr([-100, 39, 59, 55, 20]), 5) 0.28095 >>> round(npf.irr([-100, 0, 0, 74]), 5) -0.0955 >>> round(npf.irr([-100, 100, 0, -7]), 5) -0.0833 >>> round(npf.irr([-100, 100, 0, 7]), 5) 0.06206 >>> round(npf.irr([-5, 10.5, 1, -8, 1]), 5) 0.0886 ``` ``` -------------------------------- ### numpy_financial.nper Source: https://numpy.org/numpy-financial/latest/nper.html Computes the number of periodic payments for a financial calculation. It takes the interest rate per period, periodic payment amount, present value, and optionally future value and when payments are due. ```APIDOC ## numpy_financial.nper ### Description Computes the number of periodic payments. `decimal.Decimal` type is not supported. ### Method Signature `numpy_financial.nper(_rate_, _pmt_, _pv_, _fv=0_, _when='end'_) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **rate** (array_like) - Rate of interest (per period) - **pmt** (array_like) - Payment - **pv** (array_like) - Present value - **fv** (array_like, optional) - Future value. Defaults to 0. - **when** (string or int, optional) - When payments are due. Accepts 'begin' (1) or 'end' (0). Defaults to 'end'. ### Notes The number of periods `nper` is computed by solving the equation: ``` fv + pv*(1+rate)**nper + pmt*(1+rate*when)/rate*((1+rate)**nper-1) = 0 ``` but if `rate = 0` then: ``` fv + pv + pmt*nper = 0 ``` ### Examples ```python >>> import numpy as np >>> import numpy_financial as npf # If you only had $150/month to pay towards the loan, how long would it take to pay-off a loan of $8,000 at 7% annual interest? >>> print(np.round(npf.nper(0.07/12, -150, 8000), 5)) 64.07335 # So, over 64 months would be required to pay off the loan. The same analysis could be done with several different interest rates and/or payments and/or total amounts to produce an entire table. >>> npf.nper(*(np.ogrid[0.07/12: 0.08/12: 0.01/12, ... -150 : -99 : 50 , ... 8000 : 9001 : 1000])) array([[[ 64.07334877, 74.06368256], [108.07548412, 127.99022654]], [[ 66.12443902, 76.87897353], [114.70165583, 137.90124779]]]) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.