Solution 1
Solution 1
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])
flows1 = [Cashflow(-100000,0,.05),Cashflow(50000,1,.05),Cashflow(50000,2,.05),Cashflow(50000,3,.05),Cashflow(50000,4,.05),Cashflow(50000,5,.05)]
print(NPV(flows1))
The correct answer is 116473.83. I imported the two functions we created in the first two lessons, and then it was just a matter of creating the array of cash flows.
This is one way of representing it but let’s put it in the format of the equations. The $50,000 a year is an operating cash flow (revenue), and the $100,000 put into the equipment is net capital spending because we are investing in long term equipment. If we were to rearrange we would have:
NCS = [Cashflow(-100000,0,.05)]
OCF = [Cashflow(50000,1,.05),Cashflow(50000,2,.05),Cashflow(50000,3,.05),Cashflow(50000,4,.05),Cashflow(50000,5,.05)]
print(NPV(NCS)+NPV(OCF))
This works because the present value of cash flows will sum to the same thing whether we add them together before getting the present value or after we get the present value of both.
Challenge
There’s now a 5,000 fee for periods 1-5 to keep machine working, what is the present value now?