def rate(nper, pmt, pv, fv, when='<STR_LIT:end>', guess=<NUM_LIT>, tol=<NUM_LIT>, maxiter=<NUM_LIT:100>):
when = _convert_when(when)<EOL>(nper, pmt, pv, fv, when) = map(np.asarray, [nper, pmt, pv, fv, when])<EOL>rn = guess<EOL>iter = <NUM_LIT:0><EOL>close = False<EOL>while (iter < maxiter) and not close:<EOL><INDENT>rnp1 = rn - _g_div_gp(rn, nper, pmt, pv, fv, when)<EOL>diff = abs(rnp1-rn)<EOL>close = np.all(diff < tol)<EOL>iter += <NUM_LIT:1><EOL>rn = rnp1<EOL><DEDENT>if not close:<EOL><INDENT>return np.nan + rn<EOL><DEDENT>else:<EOL><INDENT>return rn<EOL><DEDENT>
Compute the rate of interest per period.

Parameters
----------
nper : array_like
    Number of compounding periods
pmt : array_like
    Payment
pv : array_like
    Present value
fv : array_like
    Future value
when : {{'begin', 1}, {'end', 0}}, {string, int}, optional
    When payments are due ('begin' (1) or 'end' (0))
guess : float, optional
    Starting guess for solving the rate of interest
tol : float, optional
    Required tolerance for the solution
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``.

References
----------
Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May). Open Document
Format for Office Applications (OpenDocument)v1.2, Part 2: Recalculated
Formula (OpenFormula) Format - Annotated Version, Pre-Draft 12.
Organization for the Advancement of Structured Information Standards
(OASIS). Billerica, MA, USA. [ODT Document]. Available:
http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formula
OpenDocument-formula-20090508.odt