-
Present Values 3
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
-
NPV vs. IRR 4
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
-
Other Profit Measures 4
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
Lecture3.4
-
-
Depreciation 4
-
Lecture4.1
-
Lecture4.2
-
Lecture4.3
-
Lecture4.4
-
-
Cash Flow Challenges 9
-
Lecture5.1
-
Lecture5.2
-
Lecture5.3
-
Lecture5.4
-
Lecture5.5
-
Lecture5.6
-
Lecture5.7
-
Lecture5.8
-
Lecture5.9
-
-
Capital Asset Pricing Model 3
-
Lecture6.1
-
Lecture6.2
-
Lecture6.3
-
-
Risky Debt 3
-
Lecture7.1
-
Lecture7.2
-
Lecture7.3
-
-
Unlevering Equity 3
-
Lecture8.1
-
Lecture8.2
-
Lecture8.3
-
-
Weighted Average Cost of Capital 4
-
Lecture9.1
-
Lecture9.2
-
Lecture9.3
-
Lecture9.4
-
-
Debt Effect Analysis 2
-
Lecture10.1
-
Lecture10.2
-
-
WACC Challenge 2
-
Lecture11.1
-
Lecture11.2
-
-
Relative Valuation 4
-
Lecture12.1
-
Lecture12.2
-
Lecture12.3
-
Lecture12.4
-
-
Forward Contract Valuation 3
-
Lecture13.1
-
Lecture13.2
-
Lecture13.3
-
Measures Part 2
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])
def pIndex(flows):
pos = [x for x in flows if x.val > 0]
neg = [x for x in flows if x.val < 0]
return NPV(pos)/-NPV(neg)
The first two lines are list comprehension like we have seen except we now have added on an if condition. Basically we get x in our array but only if its value is positive/negative depending on the array. If it does not satisfy the condition it is not added. So we in essence create a filter for both of our arrays. The last line gets the present value of both the positive and negative cash flows, we put a negative sign before the second term so that we can get a positive profitability index measure.
An example:
flows = [Cashflow(-1500,0,.05),Cashflow(1000,1,.05),Cashflow(1000,2,.05)]
print(pIndex(flows))
The rule for taking a project with this measure is that if it is >1 we want to take it. The higher the value, the more appealing that project is because we get more bang for the buck.