當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。