当前位置: 首页>>代码示例>>Python>>正文


Python numpy.irr方法代码示例

本文整理汇总了Python中numpy.irr方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.irr方法的具体用法?Python numpy.irr怎么用?Python numpy.irr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpy的用法示例。


在下文中一共展示了numpy.irr方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_irr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import irr [as 别名]
def test_irr(self):
        v = [-150000, 15000, 25000, 35000, 45000, 60000]
        assert_almost_equal(np.irr(v), 0.0524, 2)
        v = [-100, 0, 0, 74]
        assert_almost_equal(np.irr(v), -0.0955, 2)
        v = [-100, 39, 59, 55, 20]
        assert_almost_equal(np.irr(v), 0.28095, 2)
        v = [-100, 100, 0, -7]
        assert_almost_equal(np.irr(v), -0.0833, 2)
        v = [-100, 100, 0, 7]
        assert_almost_equal(np.irr(v), 0.06206, 2)
        v = [-5, 10.5, 1, -8, 1]
        assert_almost_equal(np.irr(v), 0.0886, 2)

        # Test that if there is no solution then np.irr returns nan
        # Fixes gh-6744
        v = [-1, -2, -3]
        assert_equal(np.irr(v), np.nan) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_financial.py

示例2: irr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import irr [as 别名]
def irr(values, guess = None):
    """
    Function to calculate the internal rate of return (IRR) using payments and periodic dates. It resembles the
    excel function IRR().

    Excel reference: https://support.office.com/en-us/article/IRR-function-64925eaa-9988-495b-b290-3ad0c163c1bc

    :param values: the payments of which at least one has to be negative.
    :param guess: an initial guess which is required by Excel but isn't used by this function.
    :return: a float being the IRR.
    """
    if isinstance(values, Range):
        values = values.values

    if is_not_number_input(values):
        return numeric_error(values, 'values')

    if guess is not None and guess != 0:
        raise ValueError('guess value for excellib.irr() is %s and not 0' % guess)
    else:
        try:
            return np.irr(values)
        except Exception as e:
            return ExcelError('#NUM!', e) 
开发者ID:vallettea,项目名称:koala,代码行数:26,代码来源:excellib.py

示例3: test_irr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import irr [as 别名]
def test_irr(self):
        v = [-150000, 15000, 25000, 35000, 45000, 60000]
        assert_almost_equal(np.irr(v),
                            0.0524, 2)
        v = [-100, 0, 0, 74]
        assert_almost_equal(np.irr(v),
                            -0.0955, 2)
        v = [-100, 39, 59, 55, 20]
        assert_almost_equal(np.irr(v),
                            0.28095, 2)
        v = [-100, 100, 0, -7]
        assert_almost_equal(np.irr(v),
                            -0.0833, 2)
        v = [-100, 100, 0, 7]
        assert_almost_equal(np.irr(v),
                            0.06206, 2)
        v = [-5, 10.5, 1, -8, 1]
        assert_almost_equal(np.irr(v),
                            0.0886, 2) 
开发者ID:pfchai,项目名称:ImageFusion,代码行数:21,代码来源:test_financial.py

示例4: xirr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import irr [as 别名]
def xirr(values, guess=0.1):
    with np.errstate(divide='ignore', invalid='ignore'):
        res = np.irr(tuple(flatten(text2num(replace_empty(values)).ravel())))
        res = (not np.isfinite(res)) and Error.errors['#NUM!'] or res

        def _(g):
            e = isinstance(g, str) and Error.errors['#VALUE!']
            return get_error(g, e) or res

        guess = text2num(replace_empty(guess))
        return np.vectorize(_, otypes=[object])(guess).view(Array) 
开发者ID:vinci1it2000,项目名称:formulas,代码行数:13,代码来源:financial.py

示例5: test_irr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import irr [as 别名]
def test_irr(self):
        v = [-150000, 15000, 25000, 35000, 45000, 60000]
        assert_almost_equal(np.irr(v), 0.0524, 2)
        v = [-100, 0, 0, 74]
        assert_almost_equal(np.irr(v), -0.0955, 2)
        v = [-100, 39, 59, 55, 20]
        assert_almost_equal(np.irr(v), 0.28095, 2)
        v = [-100, 100, 0, -7]
        assert_almost_equal(np.irr(v), -0.0833, 2)
        v = [-100, 100, 0, 7]
        assert_almost_equal(np.irr(v), 0.06206, 2)
        v = [-5, 10.5, 1, -8, 1]
        assert_almost_equal(np.irr(v), 0.0886, 2) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:15,代码来源:test_financial.py

示例6: test_irr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import irr [as 别名]
def test_irr(self):
        v = [-150000, 15000, 25000, 35000, 45000, 60000]
        assert_almost_equal(np.irr(v),
                            0.0524, 2) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:6,代码来源:test_financial.py

示例7: irr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import irr [as 别名]
def irr(cflo):
    """Computes the internal rate of return of a generic cashflow as a periodic
    interest rate.

    Args:
        cflo (pandas.Series): Generic cashflow.

    Returns:
        Float or list of floats.

    **Examples.**

    >>> cflo = cashflow([-200] + [100]*4, start='2000Q1', freq='Q')
    >>> irr(cflo) # doctest: +ELLIPSIS
    34.90...

    >>> irr([cflo, cflo]) # doctest: +ELLIPSIS
    0    34.90...
    1    34.90...
    dtype: float64

    """
    

    if isinstance(cflo, pd.Series):
        cflo = [cflo]
    retval = pd.Series([0] * len(cflo), dtype=np.float64)
    for index, xcflo in enumerate(cflo):
        retval[index] = (100 * np.irr(xcflo))
    if len(retval) == 1:
        return retval[0]
    return retval

## modified internal rate of return 
开发者ID:jdvelasq,项目名称:cashflows,代码行数:36,代码来源:analysis.py

示例8: xirr

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import irr [as 别名]
def xirr(values, dates, guess=0):
    """
    Function to calculate the internal rate of return (IRR) using payments and non-periodic dates. It resembles the
    excel function XIRR().

    Excel reference: https://support.office.com/en-ie/article/xirr-function-de1242ec-6477-445b-b11b-a303ad9adc9d

    :param values: the payments of which at least one has to be negative.
    :param dates: the dates as excel dates (e.g. 43571 for 16/04/2019).
    :param guess: an initial guess which is required by Excel but isn't used by this function.
    :return: a float being the IRR.
    """

    if isinstance(values, Range):
        values = values.values

    if all(value < 0 for value in values):
        return 0

    if isinstance(dates, Range):
        dates = dates.values

    if is_not_number_input(values):
        return numeric_error(values, 'values')

    if is_not_number_input(dates):
        return numeric_error(dates, 'dates')

    if guess is not None and guess != 0:
        raise ValueError('guess value for excellib.irr() is %s and not 0' % guess)
    else:
        try:
            try:
                return scipy.optimize.newton(lambda r: xnpv(r, values, dates, lim_rate_low=False, lim_rate_high=True), 0.0)
            except (RuntimeError, FloatingPointError, ExcelError):  # Failed to converge?
                return scipy.optimize.brentq(lambda r: xnpv(r, values, dates, lim_rate_low=False, lim_rate_high=True), -1.0, 1e5)
        except Exception:
            return ExcelError('#NUM', 'IRR did not converge.') 
开发者ID:vallettea,项目名称:koala,代码行数:40,代码来源:excellib.py

示例9: npv

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import irr [as 别名]
def npv(rate, values):
    """
    Returns the NPV (Net Present Value) of a cash flow series.

    Parameters
    ----------
    rate : scalar
        The discount rate.
    values : array_like, shape(M, )
        The values of the time series of cash flows.  The (fixed) time
        interval between cash flow "events" must be the same as that for
        which `rate` is given (i.e., if `rate` is per year, then precisely
        a year is understood to elapse between each cash flow event).  By
        convention, investments or "deposits" are negative, income or
        "withdrawals" are positive; `values` must begin with the initial
        investment, thus `values[0]` will typically be negative.

    Returns
    -------
    out : float
        The NPV of the input cash flow series `values` at the discount
        `rate`.

    Notes
    -----
    Returns the result of: [G]_

    .. math :: \\sum_{t=0}^{M-1}{\\frac{values_t}{(1+rate)^{t}}}

    References
    ----------
    .. [G] L. J. Gitman, "Principles of Managerial Finance, Brief," 3rd ed.,
       Addison-Wesley, 2003, pg. 346.

    Examples
    --------
    >>> np.npv(0.281,[-100, 39, 59, 55, 20])
    -0.0084785916384548798

    (Compare with the Example given for numpy.lib.financial.irr)

    """
    values = np.asarray(values)
    return (values / (1+rate)**np.arange(0, len(values))).sum(axis=0) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:46,代码来源:financial.py

示例10: npv

# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import irr [as 别名]
def npv(rate, values):
    """
    Returns the NPV (Net Present Value) of a cash flow series.

    Parameters
    ----------
    rate : scalar
        The discount rate.
    values : array_like, shape(M, )
        The values of the time series of cash flows.  The (fixed) time
        interval between cash flow "events" must be the same as that
        for which `rate` is given (i.e., if `rate` is per year, then
        precisely a year is understood to elapse between each cash flow
        event).  By convention, investments or "deposits" are negative,
        income or "withdrawals" are positive; `values` must begin with
        the initial investment, thus `values[0]` will typically be
        negative.

    Returns
    -------
    out : float
        The NPV of the input cash flow series `values` at the discount `rate`.

    Notes
    -----
    Returns the result of: [G]_

    .. math :: \\sum_{t=0}^{M-1}{\\frac{values_t}{(1+rate)^{t}}}

    References
    ----------
    .. [G] L. J. Gitman, "Principles of Managerial Finance, Brief," 3rd ed.,
       Addison-Wesley, 2003, pg. 346.

    Examples
    --------
    >>> np.npv(0.281,[-100, 39, 59, 55, 20])
    -0.0084785916384548798

    (Compare with the Example given for numpy.lib.financial.irr)

    """
    values = np.asarray(values)
    return (values / (1+rate)**np.arange(0, len(values))).sum(axis=0) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:46,代码来源:financial.py


注:本文中的numpy.irr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。