-
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
-
Solutions
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)
The valAt function moves the cash flow back or forward depending on what period you want, if we want the value of the cash flow before the date we would get a negative number for time-self.t, where as if we wanted the future value of the cash flow it would be a positive value. I added a PV attribute to the cash flow class because it is used so often in finance. Now that we have this class, we will use it to define any cash flows from now. The attribute actually gets defined from a function that we created within the class, which you are allowed to do in Python.
To solve the second challenge, I’m going to create an array for my cash flows. I will also iterate through it to find the total present value.
Solution 2
flows = [Cashflow(1000,1,.05),Cashflow(1000,2,.05)]
total =0
for f in flows:
total+= f.PV
print(total)
The present value attribute made it very easy to get the total present value. I’m going to also show a secondary way to do this that makes it faster, but might be more confusing at first, called list comprehension.
total = [f.PV for f in flows]
print(total)
print(sum(total))
The way the above code works is that we create a new array where for every cash flow “f” in flows, we get f.PV in our array. The total array will print out an array filled with the present values now, and if you use the sum() function python has we get the sum of all the elements of the array. Now to get the future value we could do one of the below ways.
total =0
for f in flows:
total+= f.valAt(3)
print(total)
total = [f.valAt(3) for f in flows]
print(total)
print(sum(total))
Both return the same values.