Well, welcome back. We're going to do something really interesting this time. We've talked a lot about why it's a good idea to use zero-coupon bonds instead of cash in your GHP because relative to your liabilities, it can be quite risky actually to use cash. If you can find a perfect set of zero-coupon bonds that match your liabilities exactly, then it would be far better to just buy those zero-coupon bonds. Of course, the problem is that it's not always easy to find these zero-coupon bonds that are perfectly matched to your liabilities. So what we're going to do in this section is, we're going to look at what we can do to get that major advantage that we got from a zero-coupon bond, and that is that regardless of what happens in the intervening period between the time I buy the bond and maturity, even though it might wander around, the nice thing about that zero-coupon bond is I know that that dollar will be there regardless of what happens to interest rates. Well, it turns out, we can do something somewhat similar here by just holding a portfolio of regular coupon-bearing bonds or coupon-paying bonds as long as we can do this factor matching or duration matching, okay? So we're going to now look at exactly how to do that, and we're going to build a portfolio of regular coupon-paying bonds that have that same advantage, that is that we can match them up to our liabilities and they will, in fact, go up and down in value relative to the liabilities when interest rates change, okay, in the same way. All right. So long story short, we're going to do something that would allow us to work around the problem of not having the perfect zero-coupon bond available to us, all right? So let's get going. This stuff here should be very simple and straightforward. You've seen this a gazillion times, so I'm just going to go ahead and do that right now. The code that I'm going to write to compute and work with regular coupon bonds is simple enough that I'm just going to actually type it right into my code right here. I've already pre-typed it. I'll just walk you through it so that you know exactly what's going on, but I feel it's simple enough that you don't want to sit and watch me type. There'll be plenty of time to do that later on down the road here. So okay. So you need two pieces of code. The first is something that actually generates the cash flows, okay? So let's look at what that is. So here's a function that generates the actual cash flows. So you give it the maturity. The principals of maturity is something like three-year bond would be. This would be three. The principal is also called the face value of the bond, that's $100. Then, there's a certain coupon rate. So it's a, let's say, three percent coupon. That basically means that it's going to pay coupons every single year equal to three percent of the principal. So that's the coupon rate, and that coupon rate is paid over the year. This tells you how many coupons per year. So a typical bond will pay once or twice a year, but there are some bonds that pay more often. We're actually going to just assume, for the most part, that most of these coupons are 12 per year because that means that we get a coupon every month, and that means we can work with monthly data much more easily and we don't have to worry about bond prices in-between one coupon and another, okay? So it's just a simplification. We don't have to worry about if you're experienced with fixed income, you might be familiar with the challenge of computing the dirty price for a bond. We don't have to do any of that stuff. So I'm just going to, for the most part, use examples where I'm going to be paying 12 coupons a year. That way, I don't have to worry about partial payments of coupons, okay, when I'm working on monthly data. Okay. This code is actually very straightforward. So let's just look at that a little bit. So how many coupons do I have to pay? Well, I have a maturity of, let's say, three years, and, let's say, there are 12 coupons per year. Then, well, I have to pay 36 coupons, right? Because I might have some round numbers here like a one and a half years or something, I've used round, okay? What is the amount of each coupon? Well, that's, obviously, very straightforward as well. It's whatever the face value is multiplied by the coupon rate and then divided by the coupons per year, okay? So that's straightforward. So now, we've got the coupon times here. When am I going to pay these coupons? I'm just going to keep it real simple. I'm just going to number these coupons starting from one. So it's going to go one, two, three, four, five, six [inaudible] if I have a three-year two times a year coupon. So I'm just going to one to six. So np.arange, it just returns an array that goes from 1 to n_coupons plus 1, this last number not included. So this would literally be the numbers 1, 2, 3, 4, 5, 6 up to n coupons. Okay. Now that we've got that, generating the actual cash flows is very, very simple because all I have to do is, it's going to generate that coupon amount once for every single coupon time, right? So if there's six of these, this will be a series of six elements, and each element will be equal to the coupon amount, right? Normally, I would have just said, we're done, except we have to increment that last payment because that's how the bond works, right? The bond will pay coupons several times a year, and then that last payment, when the bond matures, will return not just that last coupon, but also the principal. So all I'm doing here is, I'm saying, for that last cash flow, also add in the principal. Very simple. So I'm going to get the cash flows. Let's just try it just to make sure that we understand what we're doing here. So I'm going to say something like erk.bond_cash_flows. Let's say, it's a three-year bond, the principal is $100, the coupon rate is 0.03. There are, say, two coupons a year, and yeah, that's all we need. So if I go and hit that, you'll see that's exactly right, I've got six coupons. The first coupon is one and a half dollars. That's half. Why half? Because there are two coupons per year, and half of three dollars. Three dollars why? Because three percent of a face value of $100 is three dollars. So that three dollars is split into those two semi-annual coupons. Then, the last one, of course, you get that same one and a half, but you also get back the principal, okay? That's exactly what I was hoping to see, and that's good. Now, pricing a bond is actually, just literally, one line of code, and that's because, actually, I have a bug here, let me fix that. But I'll tell you in a second what it is. So let's think about this. All I'm doing to price a bond is, I generate the cash flows just by calling that code, right? Then, I'm computing the present value of those cash flows, right? Of course, I have to look at the discount rate per period. That was the mistake that I have here, so let me fix that. That's just coupons per year, right? Okay. So there you go. So what am I doing here? I've generated the cash flows, and then, I compute the present value of the cash flows, assuming some sort of a discount rate. Overall divided by the number of coupons per year. So this is the interest rate per period. Because if you remember, the code for the present value, we were just using everything was annual data. Let's try this. So let me save this, and let me go back in here, and let's try and compute the price of a bond. So let's do this. So let's erk.bond_price. Yeah, bond price. Let's try and price a 20-year bond that has $1,000 face value. Let's assume that the coupon rate is five percent. Let's assume it's two coupons per year, so it's paying semiannually. Then here, remember, that the discount rate is the discount rate to use to discount all those coupons. So that's the prevailing, that today's interest rate is the way you should think about it. What interest rate should I use in order to discount these cash flows? The answer is, well, you would discount it by whatever that radius and, of course, divided by the coupons per year because these cash flows are per period. So let's do that, and let's assume that my discount rate is 0.04. So think about what's happening and tell me what you think you should see here. So ask yourself, this is a bond that's paying a five percent coupon, but today interest rates are four percent. What would you expect to see as the price of this bond? The answer is, it's actually selling at a premium. Why? Because it's paying a coupon of five percent that is higher than the current interest rate. So let's try and compare that with, and I'm just going to copy and paste that here. Let's say, interest rates have not changed. Interest rates have not changed, and so the current interest rate is the same as the coupon rate, and you'll see that other than to within round off, you'll basically get $1,000 because that's the face value of the bond. That's exactly how bond pricing works. This is exactly what you would expect. Okay, good. So hopefully, none of this really shocks you. So what I'm now interested in doing is looking at, let's first examine the problem, how is this bond price going to change with interest rates? So for example, I've got the same thing and I can look at, let's say, 0.02, for example. Now you see that because the interest rates have fallen even further, it's selling at even more of a premium. So that we already know, as interest rates fall, bond prices rise. I'm just seeing exactly this. So let's just formalize why it is that using just a straightforward bond as a hedge is a problem. So what I'm going to do is this. I'm going to just plot it, is what it is. So let's do linspace. Linspace, I think, we've seen this before, but it just gives you a whole bunch of points. So I'm going to look at interest rates starting from one percent going up to 10 percent, and I'm going to look at 20 points along the way. So this will simply go 0.01. It'll figure out how many steps it needs in order to get there. So in fact, let's just look at it. You'll see it's 0.01, 0.0147, 0.019 blah blah, and it's basically going from 0.01 to 10 percent, one percent to 10 percent. Okay. So now I have the rates and all I'm going to do now is, I'm going to do prices. So these are the bond prices. I want to look at what are the bond prices for each of these different interest rates of this bond, and I'm going to do something that we've done once before that you might have forgotten. This is a good opportunity for you to remember that. I'm going to do something called a list comprehension. So I could have done this with a loop. I can say for are in rates, but I prefer that you start looking at these kind of more sophisticated ways of doing it. This is more Pythonic. So let's look at the more Pythonic way of doing it. So let's look at the bond price. So what we want to do is, we want to create a list of bond prices. So what we want to do is, you want to look at the bond price, of what? Let's take a 10-year bond, and let's say the face value is 1,000, and let's say the coupon was five percent, and let's say it's paying twice a year. At what rate? Well, the rate is exactly what I'm going to vary. So it's going to be some rate, for rate in rates. So you can see this is kind of an embedded for loop, but it's really nice because I don't have to say for rate in rates and then keep a temporary variable and keep constructing a list as I go. This is a much simpler way of doing it. So let's look at that, and I'm just going to print that out, and I'm going to actually print out the prices just so we can see. You see that it's basically computed a list of prices for me. So let's just plot that. So I'm going to plot. So let's do pd.DataFrame. Let's say the data is the prices and the index is the rates. What I'm going to do is, I'm going to plot that, and I'm going to plot that saying change in price of 10-year bond with different interest rates, something like that. Oops, title equals. Let's get rid of the legend, and let's give it a fig size of, let's say, 15,6. You can see what's going on here. As interest rates rise, the price of this bond is falling. That's basically what we've been able to establish, and you can see therefore, that using this 10-year bond as a hedge is not such a good idea. Why? Because the price of interest rates go up, the price of the bond is going to fall. Bad hedge. So what we're going to do is, we're going to try and construct a combination of bonds that has some resilience to interest rates in much the same way that a zero-coupon bond has a resilience to interest rates. The reason that the zero-coupon bond has resilience to interest rates, is because it basically comes down to just one payment. So in other words, if I give you $1,000 at the end of 10 years, then I know that at the end of 10 years I'm going to get those $1,000 and that's it. So interest rates in the middle don't matter. The problem with this bond is all these intermediate cash flows that are being generated. So let me explain what's going on. So if I look at the cash flows of say erk.bond_cash_flows of, let's keep it simple, a three-year bond, let's call it $1,000 face value, six percent coupon, and let's say, two payments. So let's look at what these cash flows look like. So what this means is, these are six payments in three years, so this is at the end of the third year, that is by the time I've got my sixth payment, I'm going to get 1,030 back. But along the way, I'm also getting 30 plus 30 plus 30 plus 30. So the question I should ask you is, how long am I waiting before I get my cash flows? The answer could be one of at least two ways. One way of looking at it is to say, well, you're waiting for years because that's when the last cash flow happens. But another way of looking at it is say, well, you're getting some of the cash before that last cash flow. So you can actually compute the weighted average time that it takes to get back the cash. The weighted average time. The weighted average time weighted by the amount. So in other words, I'm going to say it's six periods in this example, let's just do it in terms of periods. So there are six periods, and although I'm waiting six periods for this payment, I'm also getting some money back at the end of the fifth period, and some money back by the fourth period, and so on, and so forth. So what I can do is, I can compute the effective waiting period to get my money back. So let's do that. So these are the cash flows, we've got it, and what I'm going to do now is, I'm going to compute what are the discount factors? So again, getting this $30 back today is better than getting some $30 out in the future. So I'm going to weight them not just by the cash flows but by the present value of the cash flows. So remember how I do that. I have to find what is the present value of these cash flows, and I do that by first finding what are the discount factors. So let's look at the discounts. So let's call this discounts. The discounts is, we already have the code to do that. So I'm just going to say discount, and you have to give it how long. So I'm going to give it the index, so it's one, two, three, four, five, six. That's the number of periods. The interest rate is, what was it? Six percent. Let's say, 0.06, is what I'm assuming interest rates are. At this point, I'm not changing anything else. That's the rate by which I want to discount it per period. So let me just look at those discounts. You'll see that's how much I need to discount the first payment. So that's 97 percent, 0.97 is the discount factor for that first payment, and 0.83 is a discount factor for a payment that's six periods out. Okay, good. So now I can compute the weighted average in the following way. So the discounted cash, let's call this the discounted cash flow, is what? It's the discounts. Multiply by the actual cash flows. So let's look at the discounted cash flows. So you see, this is the discounted value or the present value of each of the cash flows given by that bond. So this bond is generating a sequence of cash flows. This is the present value of those cash flows. Sound good? So what we can do now is convert that into a set of weights by saying dcf divided by dcf.sum. If I do that, I'm going to get a set of weights. So let's call that the weights. So we've seen what the weights are. Now, all I'm going to do is I'm going to weight each of these periods. So in other words, I'm going to take the index that is, 123456 in this example. I'm going to multiply it by the discount cash flow, the weights. Actually, I can just do this, and I can sum them. So this is the weighted average of all the periods, and I get 5.57. So what this is saying is that the last payment is at six, and of those the maturity of the bond is six but the weighted average duration that I have to weight, weighted by the present value of each of the cash flows is equal to 5.57. So effectively, I'm not really weighting six years. I'm literally weighting six years for the last payment, but I've already got some before that. So the weighted average duration that I'm weighting is 5.57 years, and this number is called a Macaulay duration. The Macaulay duration is the weighted average duration, and here is the key insight. The key insight is that this is directly related to the rate of chain, the first derivative of the price with respect to interest rates. So in other words, if the interest rates moves and you have a large duration, then the price is going to move a lot. If you have a short duration, then the price will not move as much. So the duration is directly linked to the amount by which the price will change when interest rates change. So what is the duration of a zero-coupon bond? Well, there's one payment in a zero-coupon bond. So the weighted average duration of that one payment will be the duration of that payment which is the maturity. So for a zero-coupon bond, the weighted average duration which is a duration which is the Macaulay duration, the Macaulay duration is exactly the maturity. But for every non zero-coupon bond, one that paste intermediate coupons before maturity, it's going to have a duration shorter than the maturity of the bond. So this is the Macaulay duration. So let's do this. Now that we've understood what it does, let's just write the code to do that. Then let's see why this is useful to us. So I'm going to say def macaulay_duration of some kind of a bond. So let's say it has some cash flow, so you give it a bunch of cash flows, and you give it a discount rate. That's what we've been doing, that's what we just did. Again, I'll just keep this quick, and I'll say something like Computes the Macaulay Duration of a sequence of cash flows. What is it? Well, super simple. The discounted cash flows, discounted flows is what? It is just nothing more than the discount of that flows.index, whatever I'm passing. So whatever I've got here as the payment sequence, coupon Number 1, coupon Number 2, etc, flows.index, and whatever discount rate is. So just apply the discount_rate. You want the discounted cash flows, so multiplied by the cash flows itself. That's exactly what we did before. Then we said the weights is nothing more than the discounted cash flows. Is discounted_flows divided by the sum of discounted_flows. That's what we did. Then we said return the weighted average, weighted by those weights. Well, fortunately, there's a nice little function that actually does that, the average, the standard average function in NumPy actually supports weighted averages as well. So all I'm going to do is flows.index, and the weights that I'm going to pass are these weights that I just computed. So this is nothing more than the weighted average of the times rate of the cash flows, and the weights are computed by the present value of the discounted cash flows. So it's very simple, it's exactly what we did before. So let me just save this, and let's just try it. So I'm just going to try it again just to make sure that we get the same number. So I'm going to say erk.macaulay_duration. What do we use? First, we have to do with the cash flows. So erk.bond_cash_flows. Sorry, I've got this weird keyboard that still wrapping my head around. So let's do 3, 1000, is that what we called? I don't remember. But yeah, 3, 1000. Yeah. This was what we said (3,1000,.06, 2). What is the discount rate? It would be what we were using.06, and the per period discount rate is.06 divided by 2. Do that, and you get 5.5. Great. So this is the Macaulay duration. Why am I doing all of this stuff? The reason I'm doing it is because, if you can match the Macaulay duration of your bonds to the Macaulay duration of the liability, what do you get? Then you get two portfolios that have the same sensitivity, they change in the same way with changes in interest rate. So this isn't literally, the Macaulay duration is not exactly equal to the first derivative of the change in price but it is directly related to it. They're connected and exactly the same way. Therefore, if you can match the duration of your liabilities and the duration of your bonds that you're holding, then you're home free. Because as interest rates move, your liabilities are going to go up but your bond portfolio is going to go up by hopefully the same amount. This is not a perfect matching, this is not a perfect match. The reason is because this only works for parallel shifts of the yield curve if interest rates as a whole go up. But we know that the yield curve has more complex behavior. It can steepen, it can flatten, it can show added curvature. So you're going to have to work a little harder to fix those things. In other words, those are the additional other factors of the yield curve. But this is really the major one, the level of the yield curve is the major ones. So this is a very, very good place to at least to start. So let's actually do it, and then let's test it. So now, let's do the realia. So we've got everything we need. So now, I'm going to say Duration Matching. Okay. So let's do some Duration Matching. So, let's assume that we have a liability of let's say a $100,000 in 10 years time and then another liability of $100,000 in 12 years time. So let's start typing that out. So liabilities is, remember we're going to implement this as a series. What is my data? My data is, I said $100,000. Then I've got another $100,000. What are my times? The first one is due in 10 years and the second one is due in 12 years. So those are my liabilities. So first question, let's assume interest rates are four percent. So the first order of business is, so remember, I'm going to try and build a portfolio that has the same duration as my liabilities. So I have to find out what is my duration? What is the Macaulay duration of my liabilities? Well, you just take these liabilities because they're just cash-flows at the end of the day, and I'm going to say discounted by this 0.04. What this is telling you is, you've got a 10-year liability and you've got a 12-year liability but based on interest rates of 0.04, your duration is 10.96. So it's somewhere in between 10 and 12 and that's correct. It's almost exactly. It's a little less than 11 and that's a little less than halfway between the two, because of interest rates. Good. Now, if I had a zero-coupon bond, easy. I would just buy a zero-coupon bond that had duration of 10.96, that would be great. If I could go out and buy individual zero-coupon bonds of 10 years and 12 years, that would be great too. But let's assume we don't have any of that stuff. We only have two types of bonds available. We have a 10-year bond and a 15-year bond. So, let's keep it simple. Let's assume that the 10-year bond. Actually let both of them do the same thing. Each of them pay a five percent coupon once a year, and has a face value of 1,000. Real simple. So, what do we have to do? First we've got to figure out what is the duration of the bonds that we have? We know we want to construct a portfolio that has a duration of 10.96 but we can't do that unless we know the duration of the bonds that we have right now. So let's look at them. Let's find them Macaulay duration of the 10-year bond. That is erk.macaulay duration. Of what? So first we need to give it the cashflows. So we've got a way to do that already. We can compute the cashflows of the bond. That's easy. Again, we're using an interest rate of 0.04. So all I have to do is give you what the bond parameters are. Let's say it's a 10-year bond, face value is a 1,000, pays a coupon of five percent and it pays once a year. I'm just going to keep it simple. Then let's assume we also have a 20-year bond. So my 20-year bond, very similar. It's got a 20-year maturity. Everything else is exactly the same. So let's look at that, and let's look at what's the Macaulay duration of the 10-year bond and what's the Macaulay duration of the 20-year bond? Let's look at that. You can see that the 10-year bond actually has a duration of about 8.19 and the 20-year bond has a duration of about 13.5. Now, that might surprise you by the way, that the 20-year bond has a duration so much shorter, but that's just because the present value of those last payments are actually much less. So remember that the duration is the weighted average and it's weighted by the present value of each of the cashflows. It's the weighted average time that you have to wait. So good. Now we know what the durations of these things are. All we have to do is figure out what fraction of each of these two bonds I should hold. So some number times that, plus some other number times that. Let's say my weights are W1 and W2. Well, W1 times that plus one minus W1 which is W2 times that, should end up being 10.96. That's very easy for us to figure out. So what does that mean? So let's formalize this. In fact, let me just put the math down here. There you go. So let's just look at this. So what this is saying here is, I have a short bond and a long bond. My short bond is 10 years, my long bond is 20 years. So I have to put some amount of money. Some fraction in the short bond which has 8.19 and then one minus Ws the remaining weight. I'm going to put in this other bond which is the long bond, and I've got to find out what is this Ws? Such that Ws times this plus one minus Ws times that equal to 10.96. Well, that's just very simple algebra. I get Ws is the duration of. So in other words, I've just substituted. So I've got some duration for the short bond and duration for the long bond. The answer is very simple. The weight in the short bond is simply the duration of the long bond minus the duration of the target, by duration of the long bond minus the duration of the short bond. So in this particular case, you can plug in these numbers but instead of doing that, I'm just actually going to write the code to compute exactly this fraction, and let's just do exactly that. In fact, I'm just going to copy and paste it, and walk you through it. There you go. So I've got a thing called Match Durations. So I'm going to give you the cash flow of the target, I'm going to give you the cash flow the short bond, I'm giving you a cash flow of the long bond, and I'm going to give you some discount rate. All I'm going to do here, is I'm going to compute the duration of the target, the duration of the short bond, the duration of the long bond, and I'm going to return to you the weight in the short bond. Simple enough? It's all the stuff that we just did. So, let's do that. Let's do that. How would I do that? So my short bond is, let's look at the erk.bondcashflows. Sorry, I hate my keyboard. Let's say I've got a 10-year bond, $1,000 face value of five percent coupon and pays once a year. I think that's what we said. That's my short bond. Let me copy and paste that for my long bond. So my long bond has exactly the same thing except it's a 20-year bond. So now, what is my weight in the short bond? So let's call it Ws, and that is erk.match durations. I've got my liabilities here. I'm going to give it the short bonds cashflows, I'm going to give it the long bonds cashflows, and my discount rate right now I'm going to assume is four percent. Let's print out what that shows, 0.48. What that's telling you is, you have to put 48 percent of your assets in the short bond and 52 percent of your assets in the long bond. So let's do it. Let's actually do exactly that. So of course to be able to do that, first I have to price the short bond. For me to know how much of that I can buy, I need the price of the short bond. So that is of course easy. The price of the short bond is erk.bondprice I believe is what we call it. There you go, and 10, 1,000, 0.05, pays one, and let's say, like I said, my interest rates right now is that, and my long bond is almost exactly the same thing except that it's 20 years, and that's the long one. What else do I need? I need my assets. How much money do I have? So I've got a $200,000 thing. So how much money seems reasonable to start out with? Let's assume I own $130,000. So, what do I got? So now what I want to find out is what do I need in order to compute the Macaulay duration of this portfolio that I'm now going to buy. Well, I need the Macaulay duration. What I need is the cashflows that this portfolio is going to generate. Well, I know what the portfolio are going to generate. It's just going to be depending on how much of these bonds I buy. So let's call them the portfolio flows. My portfolio flows is just whatever I get from the first one, plus whatever I get from the second one, so I'm just going to concatenate them. So I'm just going to concatenate these two cashflows. What are the two cashflows? The first is the cashflows that I get from the first one and how much will I get? Well, whatever I have in my assets multiplied by, however, what that fraction that I came up with, which is Ws. So that is how much money I put in the short bond and let me divide that by the price of the short bond. So that's the number of bonds, number of the short bonds. That's a number of the short bond. Of course, I have to multiply that whole thing. So I have to multiply the cashflows that I'm going to get from that. So in other words, all I'm saying is this is the cashflows right here. That's what I did over here. This is the cashflow of the short bond, but I own several of those bonds. How many bonds? I own a_0 times w_s divided by p_short. That's the money divided by the price. So that's how much I'm going to get from the short bond, and for the long bond, I'm going to get something somewhat similar. So I'm just going to copy and paste it. I'm going to get however much money I put in the 1 minus w_s. That's the weight of a_0 that I'm going to put in my long bond, and I'm going to multiply that by that's how much I would get, and of course I have to divide it by the price of a long bond. That makes sense? So this is going to generate a set of flows for me, and now I compute the Macaulay duration of those flows. Let's call that the portfolio flows and it's 0.04. Good. So now 10.96 is the number of periods. This is the way you should look at it. In this case, the number of periods as though. It's one per year. So it works out to a number of years. So 10.96 is the duration of this particular portfolio, and if you look back to what we were looking at at the duration of the liabilities, where did I have that? I had that here, right there. It's the exact same thing. Now, let's compute the funding ratio. So the funding ratio, let's write a little extra code for that. Except the problem here is, we were just using a single asset. Now, we're much more interested in doing this with a series of assets. So that's pretty simple fixed. So all we do is we now update this to say that the assets itself could be a series of cashflows. Because remember, the assets that we're holding now are our bonds, and bonds will generate a series of cashflows. So it's a very simple fix. So all you have to do is do that. So we save that, and now let's go back and look at our funding ratio. So what I'm going to do now is I'm going to. So have the portfolio flows. So I am going to look at the funding ratio. Let's call it CFR, the cash funding ratio or the current funding ratio. Current funding ratio is erk.funding ratio. Now, because I've updated it so that it will support a bunch of cashflows, I can give it these flows. So these are my assets. My assets are a bunch of cashflows because I've bought a bunch of bonds, and this is exactly how much of each bond I bought and I know the cashflows of each bond, and so I've produced the cashflows that I now own as assets. Then, of course, we want to look at the liabilities. That's the funding ratio between that and the liabilities. Let's again, let's use 0.04. Good. So let's look at CFR, and you see that I'm pretty much funded at this point. I'm like 0.9998. So that looks like pretty good news. So let's see if we've really solved the problem. What I'm going to do now is I'm going to do the same thing that we did before. I'm going to look at a whole bunch of rates. So let's go rates is np.linspace from 0-0.1. That is from 0-10 percent, and I'll look at 20 data points along the way. What I'm going to do is I'm going to construct the funding ratio as these interest rates change for a whole bunch of different cashflows. Let's do this. So let's call this changes. So let's call this the funding ratio changes, and I'm going to construct a DataFrame to do this. pd.DataFrame because I'm going to plot it. But before I do that, let me give it some nice labels and stuff like that. So what I'm going to do first I'm going to say how is the long bond going to change? So what is the long bond? So what I'm going to do here is again the same list that we saw before, this comprehension. What I'm going to do is do the long bond. Let's do the short bond, and I'm going to come up with a list comprehension for that, and our duration matched bonds. So what are the funding ratios here? So what I have to do is I have to compute the funding ratio for the long bond and what are the long bond here? The long bond cashflows. Well, we had right there. Long bond. So whatever the long bond assets would have been compared to some liabilities, for r in rates. The other ones are going to look really similar. So let's just do all three of them. Now, for the short bond, it's going to be some whatever the short bond assets are going to look like, and for this one, we've actually already computed this. We already done this. So all I have to do now is I have to figure out what would my cashflows looks like if I had just invested 100 percent in the long bond, and this one would be if I'd invest in 100 percent in the short bond? Well, that's really easy as well because we've actually done all that work right over here. So let me just copy that. So let's call that long bond assets. If I had put 100 percent of my portfolio in the long bond, this would have been the cashflows. If I had put all of my assets in the short bond, let's call that SB, then these would have been my portfolio. It's just nothing more than the rate. It's the amount that I have divided by the price multiplied by the actual cashflows of the short bond and long bond. That's exactly what we have there, and the p flows is nothing more than the weighted combination of those two. So I think we're done with that. Now, we should be able to plot that. So let's just do FR change. That's what we called it, and let me plot it. I'm going to give it a title. Funding ratios with changes in interest rates, and let's give it a nice big fig size is let's call it 12, 6. Let's see if we did that right, and boom, there you go. Let's look at what's going on here. So first let's look at the long bond. If I had put all my money in the long bond, what would my funding ratio had been? Well, if interest rates had come down, my funding ratio would have gone up, but if interest rates had gone up, my funding ratio would have plunged. That would have dropped off big time. Not good. Now, what about if I had just put all of my money in the short bond? Well, that has a slightly different curve and that is exactly what we exploited when we did this duration matching business. But you can see that if I had just put all my money in the long bond, that would've been the cashflows and you'll see that my funding ratio would have been the opposite. If interest rates had gone down, then I would have suffered, but if interest rates had gone up, I would actually done well. So what about our friend, the duration matched portfolio? You can see that the duration matched portfolio has almost no has very subtle right about this point here, whether interest rates go up or down. So it's actually easier to see the effect on interest rates if you change the index of that, and so we do that. Now, you can actually see given today's discount rate, when these things move, it's going to move in a way such that there's almost no change in the funding ratio. So this is the basic breakthrough that you need in order to work in a world where you have actual bonds that pay coupons and where you don't have easy access to a zero-coupon bond. What you do is, you construct a portfolio using just regular old bonds which have all these intermediate payments, but you try and make sure that the liability has a duration that is matched by your assets. So you compute the duration of your liabilities, compute the duration of your assets, and if those two are not the same, then you have exposure to interest rate risk. That's basically the breakthrough that you need to get round this interest rate sensitivity problem. But as you can see, the good news is, it's really not that hard at least to do this first level matching for parallel shifts in the yield curve when interest rates generally go up or go down. I think we've covered a lot in this session. So we'll stop here and I will see you next time.