Matching Cash Flows
Here is a simple example, let’s say we have a bond that returns $100 in period 1 and $100 in period 2 that costs $170.
Let’s also say that we have a bond that returns $50 at period 1 costing $40 and a bond that returns $25 in period 1 costing $15. What would the price of matching cash flows be?
price = 40*2+15*4
print(price)
Notice it is less expensive! You could buy those cash flows and short the more expensive bond to make a $30 profit.
Now let’s set it up as an equation.
The assets…
Period | Asset 1 | Asset 2 | Total |
0 |
-40x 1 |
-15x 2 |
-40x 1 -15x 2 |
1 |
50x 1 |
0 |
50x 1 |
2 | 0 |
25x 2 |
25x 2 |
We can solve this problem as a matrix problem if we turn the cash flows for each period (not period 0 and not including the total column) into nested arrays where each array represents a time period, and the inner array represents the cash flows from each asset.
cashFlows = [[50,0],[0,25]]
assetFlows = [100,100]
np.linalg.solve(A,b) solves for the matching portfolio where A is the cash flows, and b is the assetFlows.
import numpy as np
np.linalg.solve(cashFlows,assetFlows)
And to solve for the price of the matching cash flows….
allocations = np.linalg.solve(cashFlows,assetFlows)
prices = [40,15]
print(allocations*prices)
print(sum(allocations*prices))
Challenge