The Functions Part 1
Solution
class Cashflow:
def __init__(self, val,t,r):
self.val = val
self.t = t
self.r = r
self.PV = self.valAt(0)
def valAt(self,time):
return self.val*(1+self.r)**(time-self.t)
def NPV(arr):
return sum([x.PV for x in arr])
print(NPV([Cashflow(-1500,0,.05),Cashflow(1000,1,.05),Cashflow(1000,2,.05)]))
Now let’s create an IRR function. Before we do, we need to add something to the cashflow class, a function that finds the present value of the cash flow with a given r.
Challenge
Create this class function