Python numpy.irr() Examples
The following are 30
code examples of numpy.irr().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: test_financial.py From recruit with Apache License 2.0 | 7 votes |
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)
Example #2
Source File: test_financial.py From lambda-packs with MIT License | 7 votes |
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)
Example #3
Source File: test_financial.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
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)
Example #4
Source File: test_financial.py From pySINDy with MIT License | 6 votes |
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)
Example #5
Source File: test_financial.py From coffeegrindsize with MIT License | 6 votes |
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)
Example #6
Source File: test_financial.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
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)
Example #7
Source File: excellib.py From koala with GNU General Public License v3.0 | 6 votes |
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)
Example #8
Source File: test_financial.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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)
Example #9
Source File: test_financial.py From mxnet-lambda with Apache License 2.0 | 6 votes |
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)
Example #10
Source File: test_financial.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
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)
Example #11
Source File: test_financial.py From elasticintel with GNU General Public License v3.0 | 6 votes |
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)
Example #12
Source File: test_financial.py From vnpy_crypto with MIT License | 6 votes |
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)
Example #13
Source File: test_financial.py From twitter-stock-recommendation with MIT License | 6 votes |
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)
Example #14
Source File: test_financial.py From ImageFusion with MIT License | 6 votes |
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)
Example #15
Source File: test_financial.py From Computable with MIT License | 5 votes |
def test_irr(self): v = [-150000, 15000, 25000, 35000, 45000, 60000] assert_almost_equal(np.irr(v), 0.0524, 2)
Example #16
Source File: analysis.py From cashflows with MIT License | 5 votes |
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
Example #17
Source File: test_financial.py From auto-alt-text-lambda-api with MIT License | 5 votes |
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)
Example #18
Source File: excellib.py From koala with GNU General Public License v3.0 | 5 votes |
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.')
Example #19
Source File: test_financial.py From keras-lambda with MIT License | 5 votes |
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)
Example #20
Source File: financial.py From formulas with European Union Public License 1.1 | 5 votes |
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)
Example #21
Source File: financial.py From Splunking-Crime with GNU Affero General Public License v3.0 | 4 votes |
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)
Example #22
Source File: financial.py From elasticintel with GNU General Public License v3.0 | 4 votes |
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)
Example #23
Source File: financial.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 4 votes |
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)
Example #24
Source File: financial.py From coffeegrindsize with MIT License | 4 votes |
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)
Example #25
Source File: financial.py From Carnets with BSD 3-Clause "New" or "Revised" License | 4 votes |
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)
Example #26
Source File: financial.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 4 votes |
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)
Example #27
Source File: financial.py From twitter-stock-recommendation with MIT License | 4 votes |
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)
Example #28
Source File: financial.py From keras-lambda with MIT License | 4 votes |
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)
Example #29
Source File: financial.py From ImageFusion with MIT License | 4 votes |
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)
Example #30
Source File: financial.py From mxnet-lambda with Apache License 2.0 | 4 votes |
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)