-
Return and Variance 7
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
Lecture1.4
-
Lecture1.5
-
Lecture1.6
-
Lecture1.7
-
-
Solving Equations 5
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
Lecture2.4
-
Lecture2.5
-
-
Capital Allocation Line 6
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
Lecture3.4
-
Lecture3.5
-
Lecture3.6
-
-
Diversification 3
-
Lecture4.1
-
Lecture4.2
-
Lecture4.3
-
-
Investment Sets 3
-
Lecture5.1
-
Lecture5.2
-
Lecture5.3
-
-
Portfolios 7
-
Lecture6.1
-
Lecture6.2
-
Lecture6.3
-
Lecture6.4
-
Lecture6.5
-
Lecture6.6
-
Lecture6.7
-
-
Capital and Security Market Lines 3
-
Lecture7.1
-
Lecture7.2
-
Lecture7.3
-
-
Arbitrage 3
-
Lecture8.1
-
Lecture8.2
-
Lecture8.3
-
-
Dividend Discount Model 2
-
Lecture9.1
-
Lecture9.2
-
-
Fixed Income 4
-
Lecture10.1
-
Lecture10.2
-
Lecture10.3
-
Lecture10.4
-
-
Duration and Immunization 4
-
Lecture11.1
-
Lecture11.2
-
Lecture11.3
-
Lecture11.4
-
Matching Cash Flows Function
Solution
def matchFlows(flowsAr,pricesAr,assetFlows):
allocations = np.linalg.solve(flowsAr,assetFlows)
price = allocations.dot(pricesAr)
return allocations,price
matchFlows([[50,0],[0,25]],[40,15],[100,100])
I use dot() to multiply then add all the values in our arrays.
Now, I am going to modify the function to include the price of the asset. This will let us decide if we want to buy or sell it, and I will also print out allocations and profits.
def Arbitrage(flowsAr,pricesAr,assetFlows,assetPrice):
allocations,priceFlows = matchFlows(flowsAr,pricesAr,assetFlows)
if priceFlows < assetPrice:
print("Buy the bonds with the following allocations: "+'...'.join(map(str,allocations)))
print("Sell one of the asset being replicated to offset the cashflows")
print("The payoff will be "+str(assetPrice-priceFlows))
else:
print("Buy the bonds with the following allocations: "+'...'.join(map(str,-allocations)))
print("Buy one of the asset being replicated to offset the cashflows")
print("The payoff will be "+str(priceFlows-assetPrice))
The map() function maps the function str (turning each number to a string) to each number. The ‘…’.join() function turns our array into a string with three dots between each element. Finally, take note of how negatives are used differently if we are buying or selling.
Arbitrage([[25,50],[50,0]],[40,15],[100,100],110)
Arbitrage([[25,50],[50,0]],[40,15],[100,100],60)
A final concept to introduce is arbitrage pricing theory. What this theory says is that there is more to the price of an asset than just simple beta. Imagine it as multiple betas on different factors, say exposure to oil or something else.
The way we price with APT is we have a premium on each factor (expected return for 1 “beta” minus risk-free), and we then sum all the betas mulitplied by the premiums assigned to each.
Let’s say we have factors 1, 2 and 3 which have premiums .04, .07 and .02. Then we could price an asset with betas of 1.2, -.4 and .3 (with a .01 risk-free rate) as follows….
def APT(rf,riskFactorBetas,riskFactorReturns):
return rf+np.array(riskFactorBetas).dot(riskFactorReturns)
APT(.01,[1.2,-.4,.3],[.04,.07,.02])
Source Code