def test_mirr(self): val = [-4500, -800, 800, 800, 600, 600, 800, 800, 700, 3000] assert_almost_equal(npf.mirr(val, 0.08, 0.055), 0.0666, 4) val = [-120000, 39000, 30000, 21000, 37000, 46000] assert_almost_equal(npf.mirr(val, 0.10, 0.12), 0.126094, 6) val = [100, 200, -50, 300, -200] assert_almost_equal(npf.mirr(val, 0.05, 0.06), 0.3428, 4) val = [39000, 30000, 21000, 37000, 46000] assert_(numpy.isnan(npf.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(npf.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(npf.mirr(val, Decimal('0.10'), Decimal('0.12')), Decimal('0.126094130365905145828421880')) val = [ Decimal('100'), Decimal('200'), Decimal('-50'), Decimal('300'), Decimal('-200') ] assert_equal(npf.mirr(val, Decimal('0.05'), Decimal('0.06')), Decimal('0.342823387842176663647819868')) val = [ Decimal('39000'), Decimal('30000'), Decimal('21000'), Decimal('37000'), Decimal('46000') ] assert_(numpy.isnan(npf.mirr(val, Decimal('0.10'), Decimal('0.12'))))
# rate:scalar数值,折现率。 # values:现金流。正数代表‘收入’或‘取款’,负数代表‘投资’或‘存款’。第一个值必须是初始的投资,也就是必须是负数。 # 公式:NPV=Σ(CI-CO)(1+i)^(-t) npv = npf.npv(rate=rate, values=values) print(f'净现值为:{npv:.5}') '''irr:内部收益率 一个人投资100,然后按照固定的时间间隔进行取款,[39,59,55,20]。 假设最终值是0,那么他投资的100,最终产出是173。 因为阶段性取款,收益率不是简单的做平均。而是用以下公式计算: -100 + 39/(1+r) + 59/(1+r)^2 + 55/(1+r)^3 + 20/(1+r)^4 = 0 ''' values = [-100, 39, 59, 55, 20] # values:array形式,每一期的现金流。正数代表‘收入’或‘取款’,负数代表‘投资’或‘存款’。第一个值必须是初始的投资,也就是必须是负数。 irr = npf.irr(values=values) print(f'投资金额为:¥{-values[0]}元,产出总金额为:¥{sum(values[1:])}元,内部收益率为:{irr:.5f}') '''mirr:修正内部收益率 指在一定贴现率的条件下,将投资项目的未来现金流入量按照一定的贴现率(再投资率)计算至最后一年的终值, 再将该投资项目的现金流入量的终值折算为现值,并使现金流入量的现值与投资项目的现金流出量达到价值平衡的贴现率。 这种方法同时考虑了不同的投资成本(Finance Rate)和现金再投资收益率(Reinvestment Rate)。 ''' values = [-100, 110, -110, 120] finance_rate = 0.065 reinvest_rate = 0.075 # values:现金流(必须有一个正值和一个负值),第一个值可以看做是沉没成本。 # finance_rate:现金流中使用的资金支付的利率 # reinvest_rate:将现金流再投资的收益率 mirr = npf.mirr(values=values, finance_rate=finance_rate, reinvest_rate=reinvest_rate) print(f'投资金额为:¥{-values[0]}元,产出总金额为:¥{sum(values[1:])}元,修正内部收益率:{mirr:.5f}')
#VPL - Valor Presente Líquido cf1 = np.array([-100, -50, 30, 30, 30, 30, 50, 60, 70, 80, 80]) vpl = npf.npv(wacc, cf1) vpl #TIR - Taxa interna de retorno tir = npf.irr(cf1) tir #MIRR - TIR Modificada mirr = npf.mirr(cf1, wacc, 0.10) mirr if tir > wacc: print("Projeto agrega valor") else: print("Projeto Destrói Valor") #Qual a taxa? taxa = npf.rate(nper, pmt, pv, fv) #Qual Parcela parcela = npf.pmt(rate, nper, pv) #Valuation de Padaria
NCFs.append(CFs[i]) NPV = 0 for i in range(0, numYears + 1): NPV += NCFs[i] / pow(1 + WACC, i) print("NPV: %f" % NPV) elif problemType == '4': numYears = int(input("Number of years: ")) finRate = float(input("Finance Rate (WACC): ")) / 100 invRate = float(input("Reinvestment Rate (WACC): ")) / 100 CFs = [] for i in range(0, numYears + 1): CFs.append(int(input("CF: "))) MIRR = np.mirr(CFs, finRate, invRate) * 100 print("MIRR: %f" % MIRR) elif problemType == '5': numYears = int(input("Number of years: ")) discountedRate = float(input("Discounted Rate: ")) / 100 CFs = [] for i in range(0, numYears + 1): CFs.append(int(input("CF: "))) cumCF = CFs[0] paybackPeriod = 0.000 for i in range(1, numYears + 1): cumCF += CFs[i] if cumCF >= 0: paybackPeriod += -((cumCF - CFs[i]) / CFs[i]) for j in range(i + 1, numYears + 1):