本文整理匯總了Python中numpy.npv方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.npv方法的具體用法?Python numpy.npv怎麽用?Python numpy.npv使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.npv方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_npv
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import npv [as 別名]
def test_npv(self):
assert_almost_equal(
np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2)
示例2: test_npv_decimal
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import npv [as 別名]
def test_npv_decimal(self):
assert_equal(
np.npv(Decimal('0.05'), [-15000, 1500, 2500, 3500, 4500, 6000]),
Decimal('122.894854950942692161628715'))
示例3: mirr
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import npv [as 別名]
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
示例4: mirr
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import npv [as 別名]
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
示例5: test_npv
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import npv [as 別名]
def test_npv(self):
assert_almost_equal(np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]),
122.89, 2)
示例6: mirr
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import npv [as 別名]
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
示例7: calc_opex_annualized
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import npv [as 別名]
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