ここにたくさんのコード
...
if c==excelfiles[1]:
b ==excelfiles[1]
wb = xlrd.open_workbook(a)
wb.sheet_names()
sh = wb.sheet_by_index(0)
for rownum in range(sh.nrows):
print sh.row_values(rownum)
for i in range(sheet.nrows):
cashflow = [sheet.cell_value(i,0)],[sheet.cell_value(i,1)],[sheet.cell_value(i,2)]
print cashflow
def npv(rate, cashflow):
value = cashflow[1] * ((1 + rate/100) ** (12 - cashflow[0]))
FV = 0
FV += value
return FV
def irr(cashflow, iterations = 100):
rate = 1.0
i = 0
while (cashflow[0][1] == 0):
i += 1
investment = cashflow[i][1]
for i in range(1, iterations+1):
rate *= (1 - (npv(rate, cashflow) / investment))
return rate
r = irr(cashflow)
print r
エラー/出力:
File "<pyshell#90>", line 1, in <module>
import quarterZ
File "quarterZ.py", line 65, in <module>
r = irr(cashflow) # why is list index out of range?
File "quarterZ.py", line 56, in irr
while (cashflow[0][1] == 0):
IndexError: list index out of range
リストのインデックスが範囲外である理由を誰か説明してもらえますか? そして、これを修正する方法を教えてもらえますか? 私はPythonに比較的慣れていないので、それはばかげた間違いだと確信しています。
本当にありがとう!
ここにもコードを添付しました: http://ideone.com/G5hGuK