PyCalc

Calculate better

PyCalc Help

Financial Functions


PyCalc includes a few basic functions commonly used for financial analysis.

Function List

Note that a more detailed description of each function can be found by typing (for instance) help(pv) for help on the pv function within PyCalc.

Function Description
pv(rate, nper, pmt, fv=0, when='end') Present value of a series of periodic equal payments.
fv(rate, nper, pmt, pv, when='end') Future value of a series of periodic equal payments.
nper(rate, pmt, pv, fv=0, when='end') The number of payment periods required to pay off a loan with principal pv, with regular payments of amount pmt
pmt(rate, nper, pv, fv=0, when='end') The regular equal payment required for an amortized, fixed-rate loan. (mortgage)
ipmt(rate, per, nper, pv, fv=0, when='end') The interest portion of the payment on a loan (see pmt() function). Since the interest portion changes each period, you must specify which period with theper parameter. Note that the first period is period 1 (not 0).
ppmt(rate, per, nper, pv, fv=0, when='end') The principal portion of the payment on a loan (see pmt() function). Since the principal portion changes each period, you must specify which period with theper parameter. Note that the first period is period 1 (not 0).
npv(rate, pmts) The net present value for a series of regular cash flows, using discount rate rate.
rate(nper, pmt, pv, fv, when='end', guess=None, tol=None, maxiter=100) The periodic interest rate required to pay off a loan over nper periods with regular payment pmt. This uses an iterative numerical algorithm which is not guaranteed to find an answer in all cases. The guess, tol, and maxiter parameters can be tuned to help the algorithm find the correct answer.
irr(pmts, guess=0.1, tol=1e-12, maxiter=100) The internal rate of return for a sequence of periodic cash flows. This function is currently not supported in PyCalc. Consider using mirr() instead.
mirr(values, finance_rate, reinvest_rate) The modified internal rate of return for a series of periodic cash flows, using the two given rates.

Parameters

The financial functions use a variety of parameters, which are described more fully here:

Parameter Description
rate The interest rate per period. Make sure you're consistent about what period you're using. If the pmt is a monthly payment, then the rate must be a monthly rate, for instance.
per For the ppmt() and ipmt() functions, this parameter determines which period is being calculated. This is 1-based (not 0-based).
nper The number of periods in the calculation.
pv The value of the asset at the beginning of the series of cash flows.
fv The value of the asset at the end of the series of cash flows.
pmt The regular periodic payment made for each cash flow.
when Whether the payment is made at the beginning or end of each period. end (0) is more common and is the default.
guess For iterative numerical solutions, the guess tells the algorithm what value to start with. Set this to your best guess of what the final answer will be.
tol The tolerance for the numerical algorithm. Once the answer changes by less than this amount from one iteration of the algorithm to the next, the algorithm will consider the answer to be final.
maxiter For numerical algorithms, how many iterations to run at most. If it can't find the answer in this many iterations, it fails.
finance_rate The rate at which you can effectively borrow cash for investment into your project.
reinvest_rate The rate at which you can loan cash as it is returned from your project.

Suitability

We expect these functions to be widely useful and applicable, however we cannot guarantee their accuracy in all cases. In critical applications, we recommend double-checking with a financial professional.

Source

These financial functions are a modified form of the numpy_financial functions, which are modeled after the similar functions in Microsft Excel. More advanced functions may be added in the future if there is sufficient interest.

These functions have been modified in order to work in the PyCalc environment without numpy.

Access

To use these functions, they must be imported into your Python environment with a statement like from pycalc_financial import *. As of the current version of PyCalc, this is done for you by default within the pycalcfun module which is by default included in your startup.py file.