1

http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.irr.html

仅当支付期和复合期以年为单位时,上面的链接才对我有效。如果他们在几个月或几个季度,我不知道如何使用它。

如果你了解内部收益率、现值、未来值等,你就会明白我在说什么。

IRR(Year) 的答案是 298.88%,我得到 12.22%

A列中的时间以年为单位

EXCEL 文件图像: Excel 文件图像

import xlrd
import numpy

fileWorkspace = 'C://Users/jod/Desktop/'

wb1 = xlrd.open_workbook(fileWorkspace + 'Project3.xls')
sh1 = wb1.sheet_by_index(0)

time,amount,category = [],[],[]
for a in range(2,sh1.nrows):
    time.append(int(sh1.cell(a,0).value))
    amount.append(float(sh1.cell(a,1).value))
    category.append(str(sh1.cell(a,2).value))
#print(time)
#print(amount)
#print(category)
print('\n')

p_p2 = str(sh1.cell(0,1))
p_p1 = p_p2.replace("text:'","")
pp = p_p1.replace("'","")
#print(pp)
c_p2 = str(sh1.cell(1,1))
c_p1 = c_p2.replace("text:'","")
cp = c_p1.replace("'","")
#print(cp)

netflow = 0
outflow = 0
inflow = 0
flow = 0
if pp == "Months" and cp == "Months":

    IRR = numpy.irr(amount) * 100
    print ("IRR:", round(IRR, 2), '%', '\n')

    for i in time: 
        flow = amount[i] / numpy.power((1 + (IRR/100)), time[i])
        if flow>0:                      
            inflow = inflow + flow      
        if flow<0:                      
            outflow = outflow + flow   

        #print ('Present Value (P) is:', round(flow,0), '\n')

    netflow = outflow + inflow
    print("In 2016")
    print("-------")
    print ('Outflow is: ', round(outflow,0))
    print ('Inflow is: ', round(inflow,0))
    print ('Netflow is: ', round(netflow,0), '\n')

    outflow2 = (round(outflow,0))*(1+(IRR/100))**(9)
    inflow2 = (round(inflow,0))*(1+(IRR/100))**(9)
    netflow2 = outflow2 + inflow2

    print("In 2025")
    print("-------")
    print ('Outflow is: ', round(outflow2,0))
    print ('Inflow is: ', round(inflow2,0))
    print ('Netflow is: ', round(netflow2,0), '\n')
4

2 回答 2

2

假设我们有每月的流量,例如:

flow = [-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1.4]
x = np.irr(flow)
x
0.0284361557263606

要计算 IRR,您需要使用以下公式:IRR = (1 + x)**12 - 1

(1 + x) ** 12 - 1
0.39999999999998925

如果您有季度流量,请相应地使用公式:

内部收益率 = (1 + np.irr(季度流量)) ** 4 - 1

于 2017-11-30T09:42:25.367 回答
0

根据您提供的 numPy 链接。这是针对定期 IRR,这意味着,这取决于您对“定期”的定义,它可以是每月或每年。

例如,当我按照您提供的数据进行操作时:

amount_arr = [-17.99, 7.99, -3.00, 7.99, -3.00, 7.99, -3.00, 7.99, -3.00, 7.99, -3.00, 7.99]
​
airr = np.irr(amount_arr)
​
print ('periodic IRR is %2.2f%%' %(100 * airr))
print ('annual is %2.2f%%' %(12 * (100 * airr)))

> periodic IRR is 12.22%
> annual is 146.66%

希望能帮助到你。

于 2016-06-01T13:38:10.110 回答