def test_mirr(self): v1 = [-4500,-800,800,800,600,600,800,800,700,3000] assert_almost_equal(np.mirr(v1,0.08,0.055), 0.0665, 4) v2 = [-120000,39000,30000,21000,37000,46000] assert_almost_equal(np.mirr(v2,0.10,0.12), 0.1344, 4)
def test_mirr(self): val = [-4500, -800, 800, 800, 600, 600, 800, 800, 700, 3000] assert_almost_equal(np.mirr(val, 0.08, 0.055), 0.0666, 4) val = [-120000, 39000, 30000, 21000, 37000, 46000] assert_almost_equal(np.mirr(val, 0.10, 0.12), 0.126094, 6) val = [100, 200, -50, 300, -200] assert_almost_equal(np.mirr(val, 0.05, 0.06), 0.3428, 4) val = [39000, 30000, 21000, 37000, 46000] assert_(np.isnan(np.mirr(val, 0.10, 0.12)))
def test_mirr(self): val = [-4500,-800,800,800,600,600,800,800,700,3000] assert_almost_equal(np.mirr(val, 0.08, 0.055), 0.0666, 4) val = [-120000,39000,30000,21000,37000,46000] assert_almost_equal(np.mirr(val, 0.10, 0.12), 0.126094, 6) val = [100,200,-50,300,-200] assert_almost_equal(np.mirr(val, 0.05, 0.06), 0.3428, 4) val = [39000,30000,21000,37000,46000] assert_(np.isnan(np.mirr(val, 0.10, 0.12)))
def test_mirr_decimal(self): val = [ Decimal("-4500"), Decimal("-800"), Decimal("800"), Decimal("800"), Decimal("600"), Decimal("600"), Decimal("800"), Decimal("800"), Decimal("700"), Decimal("3000"), ] assert_equal( np.mirr(val, Decimal("0.08"), Decimal("0.055")), Decimal("0.066597175031553548874239618"), ) val = [ Decimal("-120000"), Decimal("39000"), Decimal("30000"), Decimal("21000"), Decimal("37000"), Decimal("46000"), ] assert_equal( np.mirr(val, Decimal("0.10"), Decimal("0.12")), Decimal("0.126094130365905145828421880"), ) val = [ Decimal("100"), Decimal("200"), Decimal("-50"), Decimal("300"), Decimal("-200"), ] assert_equal( np.mirr(val, Decimal("0.05"), Decimal("0.06")), Decimal("0.342823387842176663647819868"), ) val = [ Decimal("39000"), Decimal("30000"), Decimal("21000"), Decimal("37000"), Decimal("46000"), ] assert_(np.isnan(np.mirr(val, Decimal("0.10"), Decimal("0.12"))))
def compute_mirr(cash_flows=list(), rate=0): """ :param cash_flows: cash flows data list :param rate: discount rate value :return: mirr value of cash_flows data list """ return np.mirr(cash_flows, rate, rate)
def test_mirr_decimal(self): val = [Decimal('-4500'), Decimal('-800'), Decimal('800'), Decimal('800'), Decimal('600'), Decimal('600'), Decimal('800'), Decimal('800'), Decimal('700'), Decimal('3000')] assert_equal(np.mirr(val, Decimal('0.08'), Decimal('0.055')), Decimal('0.066597175031553548874239618')) val = [Decimal('-120000'), Decimal('39000'), Decimal('30000'), Decimal('21000'), Decimal('37000'), Decimal('46000')] assert_equal(np.mirr(val, Decimal('0.10'), Decimal('0.12')), Decimal('0.126094130365905145828421880')) val = [Decimal('100'), Decimal('200'), Decimal('-50'), Decimal('300'), Decimal('-200')] assert_equal(np.mirr(val, Decimal('0.05'), Decimal('0.06')), Decimal('0.342823387842176663647819868')) val = [Decimal('39000'), Decimal('30000'), Decimal('21000'), Decimal('37000'), Decimal('46000')] assert_(np.isnan(np.mirr(val, Decimal('0.10'), Decimal('0.12'))))
def mirr(values, finance_rate, reinvest_rate, *args, **kwargs): """ MIRR is calculated by assuming NPV as zero :param values: Positive or negative cash flows :param finance_rate: Interest rate paid for the money used in cash flows :param reinvest_rate: Interest rate paid for reinvestment of cash flows :return: """ return np.mirr(values=values, finance_rate=float(finance_rate), reinvest_rate=float(reinvest_rate))
def npfin_practice(): # pv:年利率3%,按季度付息,每月付10,5年后获取1376.09633204,求现值 val_pv = np.pv(rate=0.03 / 4, nper=4 * 5, pmt=-10, fv=1376.09633204) print('年利率3%,按季度付息,每月付10,5年后获取1376.09633204,现值:\t{:.2f}'.format(-val_pv)) # fv:年利率3%,按季度付息,本金1000,每月付10,求5年后的终值 val_fv = np.fv(rate=0.03 / 4, nper=4 * 5, pmt=-10, pv=-1000) print('年利率3%,按季度付息,本金1000,每月付10,终值:\t{:.2f}'.format(val_fv)) # fvals = [] # for i in range(1, 11): # fvals.append(np.fv(rate=0.03/4, nper=4*i, pmt=-10, pv=-1000)) # plt.plot(fvals, 'bo') # plt.title('年利率3%,按季度付息,本金1000,每月付10,1-10年后的终值') # plt.show() # pmt:年利率1%,贷款1000万,求每月的分期付款 val_pmt = np.pmt(rate=0.01 / 12, nper=12 * 30, pv=10000000) print('年利率1%,贷款1000万,每月的分期付款:\t{:.2f}'.format(-val_pmt)) # nper:年利率10%,贷款9000,每月付款100,求付款期数 val_nper = np.nper(rate=0.10 / 12, pmt=-100, pv=9000) print('年利率10%,贷款9000,每月付款100,付款期数:\t{:.2f}'.format(val_nper)) # irr:现金流[-100, 38, 48, 90, 17, 36],求内部收益率 val_irr = np.irr(values=[-100, 38, 48, 90, 17, 36]) print('现金流[-100, 38, 48, 90, 17, 36],内部收益率:\t{:.0f}%'.format(100 * val_irr)) # mirr:现金流[-100, 38, 48, 90, 17, 36],投资成本3%,现金再投资收益率3%,求修正内部收益率 val_mirr = np.mirr(values=[-100, 38, 48, 90, 17, 36], finance_rate=0.03, reinvest_rate=0.03) print('现金流[-100, 38, 48, 90, 17, 36],投资成本3%,现金再投资收益率3%,求修正内部收益率:\t{:.0f}%'\ .format(100 * val_mirr)) # rate:贷款9000,每月付100,贷款167个月,求利率 val_rate = 12 * np.rate(nper=167, pmt=-100, pv=9000, fv=0) print('贷款9000,每月付100,贷款167个月,利率:\t{:.0f}%'.format(100 * val_rate)) # npv:随机在0-100之间取5个数作为现金流,利率3%,求净现值 cashflows = np.random.randint(100, size=5) cashflows = np.insert(cashflows, 0, -100) print('Cashflows: {}'.format(cashflows)) val_npv = np.npv(rate=0.03, values=cashflows) print('利率3%,上述现金流下,净现值:\t{:.2f}'.format(val_npv))
def mirr(cflo, finance_rate=0, reinvest_rate=0): """Computes the modified internal rate of return of a generic cashflow as a periodic interest rate. Args: cflo (pandas.Series): Generic cashflow. finance_rate (float): Periodic interest rate applied to negative values of the cashflow. reinvest_rate (float): Periodic interest rate applied to positive values of the cashflow. Returns: Float or list of floats. **Examples.** >>> cflo = cashflow([-200] + [100]*4, start='2000Q1', freq='Q') >>> mirr(cflo) # doctest: +ELLIPSIS 18.92... >>> mirr([cflo, cflo]) # doctest: +ELLIPSIS 0 18.920712 1 18.920712 dtype: float64 """ # negativos: finance_rate # positivos: reinvest_rate 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.mirr(xcflo, finance_rate, reinvest_rate)) if len(retval) == 1: return retval[0] return retval
def mirr(cflo, finance_rate=0, reinvest_rate=0): """Computes the modified internal rate of return. Args: cashflow (list, cashflow): cashflow. finance_rate (float): rate applied to negative values of the cashflow reinvest_rate (float): rate applied to positive values of the cashflow Returns: (float) modified internal rate of return. """ # negativos: finance_rate # positivos: reinvest_rate if isinstance(cflo, TimeSeries): cflo = [cflo] retval = [] for xcflo in cflo: retval.append(100 * xcflo.pyr * np.mirr(xcflo.tolist(), finance_rate, reinvest_rate)) if len(retval) == 1: return retval[0] return retval
cashflow = pd.concat( [dfcash_A['Cash_Flows'], dfcash_B['Cash_Flows']], axis=1 ) #found through trail and error best way to join the dataframes in one df through their indexes cashflow.columns = ['Cash Flows A', 'Cash Flows B'] print( "\nQuestion 11:\n{}\na)The payback period for Project A is {}yrs.\nb)The payback period for Project B is {}yrs.\n\n{}\n{}\nc) The \ discounted payback period for Project A is {}yrs.\nd) The discounted payback period for Project B is {}yrs.\ne) The NPV for project A is ${:,.2f}.\nf) The NPV for project B is ${:,.2f}.\ng) The IRR for project A is {}%.\nh) The IRR for project B is {}%.\ \ni) The PI for project A is {}.\nj) The PI for project B is {}.".format( cashflow, period_A, period_B, npv_data_A, npv_data_B, period_Ad, period_Bd, npv_A, npv_B, irr_A, irr_B, PI_A, PI_B)) # Question 12 npv, npv_data, irr_Discount, dfcash_A, period_A, PI = calc_npv( 4, -36429.3, [12000, 14700, 16600, 13700], 9 / 100, 3 ) #discounting appraoch: returned last year cash outflow to PV and added it to intial cost to derrive MIRR (Discount) irr_reinvest = round( np.mirr([-29800, 12000, 14700, 16600, 13700, -10200], 9 / 100, 9 / 100) * 100, 4) irr_combination = round( np.mirr([-36429.3, 12000, 14700, 16600, 13700], 9 / 100, 9 / 100) * 100, 4) print( "\nQuestion 12:\n{}\na) The MIRR using discounting approach is {}%.\nb) The MIRR using reinvestment approach is {}%.\nc) The MIRR using combination approach is {}%." .format(dfcash_A, irr_Discount, irr_reinvest, irr_combination)) # Question 13 npv, npv_data, irr_Discount, dfcash_B, period_A, PI = calc_npv( 4, -15870.531, [6100, 6700, 6200, 5100], 9 / 100, 3 ) #discounting appraoch: returned last year cash outflow to PV and added it to intial cost to derrive MIRR (Discount) irr_reinvest = round( (np.mirr([-13200, 6100, 6700, 6200, 5100, -4500], 11 / 100, 9 / 100)) * 100, 4) irr_combination = round( (np.mirr([-15870.531, 6100, 6700, 6200, 5100], 11 / 100, 9 / 100)) * 100,
def test_mirr(self): v1 = [-4500, -800, 800, 800, 600, 600, 800, 800, 700, 3000] assert_almost_equal(np.mirr(v1, 0.08, 0.055), 0.0665, 4) v2 = [-120000, 39000, 30000, 21000, 37000, 46000] assert_almost_equal(np.mirr(v2, 0.10, 0.12), 0.1344, 4)
import numpy as np print(np.fv(0.02, 20 * 12, -100, -100)) print(np.pv(0.02, 20 * 12, -100, 586032.549)) print(np.npv(0.281, [-100, 823, 59, 55, 20])) print(np.pmt(0.02 / 12, 20 * 12, 1000000)) print(np.ppmt(0.02 / 12, -100, 20 * 12, 1000000)) print(np.ipmt(0.02 / 12, 0.001, 20 * 12, 200000)) print(round(np.irr([-5, 10.5, 1, -8, 1]), 5)) print(np.mirr([-100, 823, 59, 55, 20], -100, -150)) print(np.nper(0.02, -1e7, 1e8)) print(np.rate(0.7, -1e8, 200000, 0))
import numpy as np print "Modified internal rate of return", np.mirr([-100, 38, 48, 90, 17, 36], 0.03, 0.03)
def test_mirr(self): assert_almost_equal(np.mirr((100, 200, -50, 300, -200), .05, .06), 0.342823387842, 8)
import numpy values = [1, 2, 3] finance_rate = 1 reinvest_rate = 1 numpy.mirr(values, finance_rate, reinvest_rate)
def test_mirr(self): assert_almost_equal(np.mirr((100, 200,-50, 300,-200), .05, .06), 0.342823387842, 8)