# Python numpy.npv() Examples

The following are 30 code examples for showing how to use numpy.npv(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module , or try the search function .

Example 1
```def test_npv(self):
assert_almost_equal(
np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2) ```
Example 2
```def test_npv_decimal(self):
assert_equal(
np.npv(Decimal('0.05'), [-15000, 1500, 2500, 3500, 4500, 6000]),
Decimal('122.894854950942692161628715')) ```
Example 3
```def mirr(values, finance_rate, reinvest_rate):
"""
Modified internal rate of return.

Parameters
----------
values : array_like
Cash flows (must contain at least one positive and one negative
value) or nan is returned.  The first value is considered a sunk
cost at time zero.
finance_rate : scalar
Interest rate paid on the cash flows
reinvest_rate : scalar
Interest rate received on the cash flows upon reinvestment

Returns
-------
out : float
Modified internal rate of return

"""
values = np.asarray(values)
n = values.size

# Without this explicit cast the 1/(n - 1) computation below
# becomes a float, which causes TypeError when using Decimal
# values.
if isinstance(finance_rate, Decimal):
n = Decimal(n)

pos = values > 0
neg = values < 0
if not (pos.any() and neg.any()):
return np.nan
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1/(n - 1))*(1 + reinvest_rate) - 1 ```
Example 4
```def mirr(values, finance_rate, reinvest_rate):
"""
Modified internal rate of return.

Parameters
----------
values : array_like
Cash flows (must contain at least one positive and one negative
value) or nan is returned.  The first value is considered a sunk
cost at time zero.
finance_rate : scalar
Interest rate paid on the cash flows
reinvest_rate : scalar
Interest rate received on the cash flows upon reinvestment

Returns
-------
out : float
Modified internal rate of return

"""
values = np.asarray(values)
n = values.size

# Without this explicit cast the 1/(n - 1) computation below
# becomes a float, which causes TypeError when using Decimal
# values.
if isinstance(finance_rate, Decimal):
n = Decimal(n)

pos = values > 0
neg = values < 0
if not (pos.any() and neg.any()):
return np.nan
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1/(n - 1))*(1 + reinvest_rate) - 1 ```
Example 5
```def test_npv(self):
assert_almost_equal(
np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2) ```
Example 6
```def mirr(values, finance_rate, reinvest_rate):
"""
Modified internal rate of return.

Parameters
----------
values : array_like
Cash flows (must contain at least one positive and one negative
value) or nan is returned.  The first value is considered a sunk
cost at time zero.
finance_rate : scalar
Interest rate paid on the cash flows
reinvest_rate : scalar
Interest rate received on the cash flows upon reinvestment

Returns
-------
out : float
Modified internal rate of return

"""
values = np.asarray(values, dtype=np.double)
n = values.size
pos = values > 0
neg = values < 0
if not (pos.any() and neg.any()):
return np.nan
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1.0/(n - 1))*(1 + reinvest_rate) - 1 ```
Example 7
```def test_npv(self):
assert_almost_equal(
np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2) ```
Example 8
```def mirr(values, finance_rate, reinvest_rate):
"""
Modified internal rate of return.

Parameters
----------
values : array_like
Cash flows (must contain at least one positive and one negative
value) or nan is returned.  The first value is considered a sunk
cost at time zero.
finance_rate : scalar
Interest rate paid on the cash flows
reinvest_rate : scalar
Interest rate received on the cash flows upon reinvestment

Returns
-------
out : float
Modified internal rate of return

"""
values = np.asarray(values, dtype=np.double)
n = values.size
pos = values > 0
neg = values < 0
if not (pos.any() and neg.any()):
return np.nan
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1.0/(n - 1))*(1 + reinvest_rate) - 1 ```
Example 9
```def test_npv(self):
assert_almost_equal(
np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2) ```
Example 10
```def test_npv_decimal(self):
assert_equal(
np.npv(Decimal('0.05'), [-15000, 1500, 2500, 3500, 4500, 6000]),
Decimal('122.894854950942692161628715')) ```
Example 11
```def mirr(values, finance_rate, reinvest_rate):
"""
Modified internal rate of return.

Parameters
----------
values : array_like
Cash flows (must contain at least one positive and one negative
value) or nan is returned.  The first value is considered a sunk
cost at time zero.
finance_rate : scalar
Interest rate paid on the cash flows
reinvest_rate : scalar
Interest rate received on the cash flows upon reinvestment

Returns
-------
out : float
Modified internal rate of return

"""
values = np.asarray(values)
n = values.size

# Without this explicit cast the 1/(n - 1) computation below
# becomes a float, which causes TypeError when using Decimal
# values.
if isinstance(finance_rate, Decimal):
n = Decimal(n)

pos = values > 0
neg = values < 0
if not (pos.any() and neg.any()):
return np.nan
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1/(n - 1))*(1 + reinvest_rate) - 1 ```
Example 12
```def test_npv(self):
assert_almost_equal(np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2) ```
Example 13
```def mirr(values, finance_rate, reinvest_rate):
"""
Modified internal rate of return.

Parameters
----------
values : array_like
Cash flows (must contain at least one positive and one negative value)
or nan is returned.  The first value is considered a sunk cost at time zero.
finance_rate : scalar
Interest rate paid on the cash flows
reinvest_rate : scalar
Interest rate received on the cash flows upon reinvestment

Returns
-------
out : float
Modified internal rate of return

"""

values = np.asarray(values, dtype=np.double)
n = values.size
pos = values > 0
neg = values < 0
if not (pos.any() and neg.any()):
return np.nan
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1.0/(n - 1))*(1 + reinvest_rate) - 1 ```
Example 14
```def test_npv(self):
assert_almost_equal(
np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2) ```
Example 15
```def test_npv_decimal(self):
assert_equal(
np.npv(Decimal('0.05'), [-15000, 1500, 2500, 3500, 4500, 6000]),
Decimal('122.894854950942692161628715')) ```
Example 16
```def mirr(values, finance_rate, reinvest_rate):
"""
Modified internal rate of return.

Parameters
----------
values : array_like
Cash flows (must contain at least one positive and one negative
value) or nan is returned.  The first value is considered a sunk
cost at time zero.
finance_rate : scalar
Interest rate paid on the cash flows
reinvest_rate : scalar
Interest rate received on the cash flows upon reinvestment

Returns
-------
out : float
Modified internal rate of return

"""
values = np.asarray(values)
n = values.size

# Without this explicit cast the 1/(n - 1) computation below
# becomes a float, which causes TypeError when using Decimal
# values.
if isinstance(finance_rate, Decimal):
n = Decimal(n)

pos = values > 0
neg = values < 0
if not (pos.any() and neg.any()):
return np.nan
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1/(n - 1))*(1 + reinvest_rate) - 1 ```
Example 17
```def test_npv(self):
assert_almost_equal(
np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2) ```
Example 18
```def test_npv_decimal(self):
assert_equal(
np.npv(Decimal('0.05'), [-15000, 1500, 2500, 3500, 4500, 6000]),
Decimal('122.894854950942692161628715')) ```
Example 19
```def mirr(values, finance_rate, reinvest_rate):
"""
Modified internal rate of return.

Parameters
----------
values : array_like
Cash flows (must contain at least one positive and one negative
value) or nan is returned.  The first value is considered a sunk
cost at time zero.
finance_rate : scalar
Interest rate paid on the cash flows
reinvest_rate : scalar
Interest rate received on the cash flows upon reinvestment

Returns
-------
out : float
Modified internal rate of return

"""
values = np.asarray(values)
n = values.size

# Without this explicit cast the 1/(n - 1) computation below
# becomes a float, which causes TypeError when using Decimal
# values.
if isinstance(finance_rate, Decimal):
n = Decimal(n)

pos = values > 0
neg = values < 0
if not (pos.any() and neg.any()):
return np.nan
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1/(n - 1))*(1 + reinvest_rate) - 1 ```
Example 20
```def calc_opex_annualized(OpC_USDyr, Inv_IR_perc, Inv_LT_yr):
Inv_IR = Inv_IR_perc / 100
opex_list = [0.0]
opex_list.extend(Inv_LT_yr * [OpC_USDyr])
opexnpv = np.npv(Inv_IR, opex_list)
EAC = ((opexnpv * Inv_IR) / (1 - (1 + Inv_IR) ** (-Inv_LT_yr)))  # calculate positive EAC
return EAC ```
Example 21
```def test_npv(self):
assert_almost_equal(
np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2) ```
Example 22
```def test_npv_decimal(self):
assert_equal(
np.npv(Decimal('0.05'), [-15000, 1500, 2500, 3500, 4500, 6000]),
Decimal('122.894854950942692161628715')) ```
Example 23
```def mirr(values, finance_rate, reinvest_rate):
"""
Modified internal rate of return.

Parameters
----------
values : array_like
Cash flows (must contain at least one positive and one negative
value) or nan is returned.  The first value is considered a sunk
cost at time zero.
finance_rate : scalar
Interest rate paid on the cash flows
reinvest_rate : scalar
Interest rate received on the cash flows upon reinvestment

Returns
-------
out : float
Modified internal rate of return

"""
values = np.asarray(values)
n = values.size

# Without this explicit cast the 1/(n - 1) computation below
# becomes a float, which causes TypeError when using Decimal
# values.
if isinstance(finance_rate, Decimal):
n = Decimal(n)

pos = values > 0
neg = values < 0
if not (pos.any() and neg.any()):
return np.nan
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1/(n - 1))*(1 + reinvest_rate) - 1 ```
Example 24
```def mirr(values, finance_rate, reinvest_rate):
"""
Modified internal rate of return.

Parameters
----------
values : array_like
Cash flows (must contain at least one positive and one negative
value) or nan is returned.  The first value is considered a sunk
cost at time zero.
finance_rate : scalar
Interest rate paid on the cash flows
reinvest_rate : scalar
Interest rate received on the cash flows upon reinvestment

Returns
-------
out : float
Modified internal rate of return

"""
values = np.asarray(values, dtype=np.double)
n = values.size
pos = values > 0
neg = values < 0
if not (pos.any() and neg.any()):
return np.nan
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1.0/(n - 1))*(1 + reinvest_rate) - 1 ```
Example 25
```def test_npv(self):
assert_almost_equal(
np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2) ```
Example 26
```def test_npv_decimal(self):
assert_equal(
np.npv(Decimal('0.05'), [-15000, 1500, 2500, 3500, 4500, 6000]),
Decimal('122.894854950942692161628715')) ```
Example 27
```def mirr(values, finance_rate, reinvest_rate):
"""
Modified internal rate of return.

Parameters
----------
values : array_like
Cash flows (must contain at least one positive and one negative
value) or nan is returned.  The first value is considered a sunk
cost at time zero.
finance_rate : scalar
Interest rate paid on the cash flows
reinvest_rate : scalar
Interest rate received on the cash flows upon reinvestment

Returns
-------
out : float
Modified internal rate of return

"""
values = np.asarray(values)
n = values.size

# Without this explicit cast the 1/(n - 1) computation below
# becomes a float, which causes TypeError when using Decimal
# values.
if isinstance(finance_rate, Decimal):
n = Decimal(n)

pos = values > 0
neg = values < 0
if not (pos.any() and neg.any()):
return np.nan
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1/(n - 1))*(1 + reinvest_rate) - 1 ```
Example 28
```def test_npv(self):
assert_almost_equal(
np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2) ```
Example 29
```def mirr(values, finance_rate, reinvest_rate):
"""
Modified internal rate of return.

Parameters
----------
values : array_like
Cash flows (must contain at least one positive and one negative
value) or nan is returned.  The first value is considered a sunk
cost at time zero.
finance_rate : scalar
Interest rate paid on the cash flows
reinvest_rate : scalar
Interest rate received on the cash flows upon reinvestment

Returns
-------
out : float
Modified internal rate of return

"""
values = np.asarray(values, dtype=np.double)
n = values.size
pos = values > 0
neg = values < 0
if not (pos.any() and neg.any()):
return np.nan
numer = np.abs(npv(reinvest_rate, values*pos))
denom = np.abs(npv(finance_rate, values*neg))
return (numer/denom)**(1.0/(n - 1))*(1 + reinvest_rate) - 1 ```
Example 30
```def test_npv(self):