(Note: For people who have background knowledge, I am trying to follow Section 6 of Gurkaynak, Sack, and Wright (2007). If you aren't in this field it's fine, you may ignore this note)
I am trying to get bond prices given coupons and a given yield curve that is generated on a daily interval with the maturity going up to 360 months. In other words, I am trying to get present values given cash flows and discount rates. For bonds, [cash flows = coupon payments] and [discount rate = yield curve].
The first dataset that I have is the yield curve data. Below is the sample for two days for only certain maturities. So each day there are 360 different rates (ZBR) constructing the yield curve. These are all annulized rates. Since it is too long to show in the post I attached the sample data.
data yieldcurve;
input date maturity_m ZBR best32.;
format date yymmddn8.;
datalines;
20060228 1 4.016226538
20060228 2 4.0760471
20060228 8 4.324513459
20060228 14 4.33614917
20060228 20 4.294754965
20060228 206 4.623988821
20060228 358 4.483623368
20060228 359 4.482571516
20060228 360 4.481526714
20061130 1 4.020125424
20061130 2 4.081633352
20061130 3 4.140666573
20061130 4 4.194456616
20061130 358 4.482659361
20061130 359 4.48166473
20061130 360 4.480678104
;
run;
The next data I have is the bond data. Two different bonds each showing 5 different dates. Coupon rates are in percentages. But we shall assume those as dollar amounts in this context. Next coupon payment dates are shown in the last column. Again I attached the sample data.
data bond;
input CUSIP $9. DATE MATURITY COUPON nextcoup best32.;
format date maturity nextcoup yymmddn8.;
datalines;
00077TAA2 20060228 20230515 7.75 20060515
00077TAA2 20061130 20230515 7.75 20070515
00077TAA2 20070630 20230515 7.75 20071115
00077TAA2 20070731 20230515 7.75 20071115
00077TAA2 20071031 20230515 7.75 20071115
00077TAB0 20060531 20931015 7.125 20061015
00077TAB0 20060831 20931015 7.125 20061015
00077TAB0 20060930 20931015 7.125 20061015
00077TAB0 20061130 20931015 7.125 20070415
00077TAB0 20070331 20931015 7.125 20070415
;
run;
So each coupon (=cash flow) is half the coupon rate since they are paid twice a year, every 6 months. From the first observation, the cash flow should be 7.75/2 = 3.875, which is going to be paid on 20060515. These are all fixed coupon bonds so the cash flow for each bond is constant every 6 months.
Now let me show what I want to do. For the first obseravtion, the next payment date is in approximately 2 months (=20060515 - 20060228). So I would find the proper discount rate from the first table, on 20060228 with maturity = 2 months. Hence I want to discount the first cash flow, 3.875, with the discount rate, 4.0760471 by 2 months.
cf_1 = 3.875 / ((1 + 4.0760471/100)^(2/12))
The next would be
cf_2 = 3.875 / ((1 + 4.324513459/100)^(8/12)) cf_3 = 3.875 / ((1 + 4.33614917/100)^(14/12)) ... cf_35 = 3.875 / ((1+ 4.623988821/100)^(206/12)) cf_face = 100 / ((1+ 4.623988821/100)^(206/12))
Note that cf_face is the discounted face value which occurs with the last coupon payment, hence the same discount rate and time(maturity). Then,
price = sum(cf_n)
is what I want for the first observation.
Then I should move on to the next observation at date = 20061130 and repeat the same process.
I think using hash and array should be the best way, but I couldn't figure where to start. I think loading the first data into hash table and somehow use the number of months as the index to locate the ZBR should be the key.
Any help is appreciated!
... View more