numpy.irr returns error: ValueError("Input must be a rank-1 array.")

1.5k views Asked by At

Im trying to calculate the IRR of a monthly savings plan using the numpy.IRR function. I keep getting an ValueError("Input must be a rank-1 array.").

How can I turn my array "Cashflow" into an array that does not yield this error? I have tried "ravel" or "numpy.reshape" but I keep getting the error. Or is there another mistake? Thanks, R.

Here is the code:

import numpy as np
i=0
InitialPayment=2500
NumberOfPayments=225
Payment=100
MonthsToMaturity=240
FV=50000
Cashflow=[(0-InitialPayment)]
while i< NumberOfPayments:
    Cashflow.append (0-Payment)
    i +=1
while i< (MonthsToMaturity):
    Cashflow.append (0)
    i  +=1
Cashflow.append (FV)
Cashflow = np.reshape(Cashflow,-1)
print ("Cashflow: ") +str(Cashflow)
IRR = np.irr([Cashflow])
print ("IRR") +str(IRR)
0

There are 0 answers