|
From: Random U. <qld...@gm...> - 2020-12-02 07:59:58
|
Hello all -
I'm trying to build a fitted US Treasury curve using FittedBondCurve().
However, my results are odd for two reasons. (1) the shape of the curve is
a straight line and not concave as one might expect (2) the yields of the
modeled term structure are within a very tight range for the entire curve
and well below even the lowest yields in the yield dataset that is being
fit (yields being fit are shown in the dataframe below).
The only possible issues I can suspect are day count issues in my
dateparams (unclear why) or the function being able to fit multiple data
points for a single maturity. On this second point, for example, I'm trying
to model all outstanding Treasuries, so there are several bonds that sit at
the same maturity point (eg. at the 1Y point there could be an originally
issued 2Y bond that has aged 1 year along with an originally issued 30Y
bond that has aged 29 years etc.).
I've included the relatively short code along with the dataset being fit to
hopefully ease replication. This is very close to the QuantLib example for
the function with the major difference that I'm trying to fit actual bond
prices (the df that is referenced is shown in full below). Please let me
know if you need more information. Thanks for any help!
### Please load df shown at the bottom of the code before running
df <- df[order(df$YrsToMat),]
row.names(df)<-NULL
YrsToMat <- df$YrsToMat
marketQuotes <- df$Prices
cpn_rates <- df$Coupons
# I used these parameters from the QuantLib cookbook where a Treasury curve
was bootstrapped (page 101) - Treasuries settle T+1 and are Actual/Actual,
but the ActualActual.Bond dayCounter seems to give even worse results.
dateparams <- list(settlementDays=0, period="Semiannual",
dayCounter="Thirty360",
businessDayConvention ="Unadjusted")
curveparams <- list(method="ExponentialSplinesFitting",
origDate = Sys.Date())
curve <- FittedBondCurve(curveparams, YrsToMat, cpn_rates, marketQuotes,
dateparams)
z <- zoo::zoo(curve$table$zeroRates, order.by=curve$table$date)
plot(z)
df = structure(list(ISIN = c("US9128285R78", "US912828G534",
"US912828U659",
"US912828YT13", "US9128285V80", "US912828G872", "US912828U816",
"US912828YZ72", "US9128286C90", "US912828H862", "US912828SF82",
"US912828V723", "US912828Z609", "US9128286H87", "US912828J439",
"US912828W556", "US912828ZA13", "US9128286M72", "US912828J769",
"US912828W895", "US912828ZG82", "US9128286U98", "US912828SV33",
"US912828WZ90", "US912828X471", "US912828ZM50", "US9128286Y11",
"US912828XD79", "US912828XR65", "US912828ZR48", "US9128287C81",
"US912828XG01", "US912828XW50", "US912828ZX16", "US9128282P40",
"US912828XQ82", "US91282CAC55", "US912810EM63", "US912828TJ95",
"US912828YA22", "US9128282S88", "US912828L245", "US912828YF19",
"US91282CAG69", "US9128282W90", "US912828L575", "US912828YK04",
"US91282CAN11", "US912810EN47", "US9128283C28", "US912828M490",
"US912828TY62", "US91282CAR25", "US912828M805", "US912828YW42",
"US91282CAX92", "US912828N308", "US912828Z294", "US912810EP94",
"US9128283U26", "US912828P386", "US912828UN88", "US912828Z864",
"US9128284A52", "US912828P790", "US912828ZD51", "US9128284D91",
"US912828Q293", "US912828ZH65", "US9128284L18", "US912828R283",
"US912828VB32", "US912828ZP81", "US9128284S60", "US912828R697",
"US912828ZU76", "US9128284U17", "US912828S356", "US912828ZY98",
"US912810EQ77", "US912828S927", "US912828VS66", "US912828Y610",
"US91282CAF86", "US9128282D10", "US9128284X55", "US91282CAK71",
"US9128285D82", "US912828T263", "US91282CAP68", "US9128285K26",
"US912828T917", "US912828WE61", "US91282CAW10", "US9128285P13",
"US912828U576", "US9128285U08", "US912828V236", "US9128285Z94",
"US912828B667", "US912828V806", "US9128286G05", "US912828W481",
"US912828W713", "US9128286R69", "US912828WJ58", "US912828X703",
"US912828XT22", "US9128286Z85", "US912828XX34", "US9128282N91",
"US912828D564", "US912828Y875", "US9128282U35", "US912828YE44",
"US9128282Y56", "US912828YH74", "US912810ES34", "US9128283D01",
"US912828G385", "US912828YM69", "US9128283J70", "US912828YV68",
"US9128283P31", "US912828YY08", "US912810ET17", "US9128283V09",
"US912828J272", "US912828Z526", "US9128283Z13", "US912828ZC78",
"US9128284F40", "US912828ZF00", "US9128284M90", "US912828XB14",
"US912828ZL77", "US9128284R87", "US912828ZT04", "US912828XZ81",
"US912828ZW33", "US912810EV62", "US912828K742", "US912828Y792",
"US91282CAB72", "US9128284Z04", "US91282CAJ09", "US9128285C00",
"US91282CAM38", "US9128285J52", "US912828M565", "US91282CAT80",
"US9128285N64", "US91282CAZ41", "US9128285T35", "US912810EW46",
"US9128286A35", "US912828P469", "US9128286F22", "US9128286L99",
"US9128286S43", "US912828R366", "US9128286X38", "US9128287B09",
"US912810EX29", "US9128282A70", "US912828Y958", "US912828YD60",
"US912828YG91", "US912810EY02", "US912828U246", "US912828YQ73",
"US912828YU85", "US912828YX25", "US912810EZ76", "US912828V988",
"US912828Z781", "US912828ZB95", "US912828ZE35", "US912828X885",
"US912828ZN34", "US912828ZS21", "US912828ZV59", "US912810FA17",
"US9128282R06", "US91282CAD39", "US91282CAH43", "US91282CAL54",
"US912810FB99", "US9128283F58", "US91282CAU53", "US91282CAY75",
"US9128283W81", "US9128284N73", "US912810FE39", "US9128284V99",
"US912810FF04", "US9128285M81", "US912810FG86", "US9128286B18",
"US9128286T26", "US912810FJ26", "US912828YB05", "US912828YS30",
"US912828Z948", "US912810FM54", "US912828ZQ64", "US91282CAE12",
"US91282CAV37", "US912810FP85", "US912810FT08", "US912810PT97",
"US912810PU60", "US912810PW27", "US912810PX00", "US912810QA97",
"US912810QB70", "US912810QC53", "US912810QD37", "US912810QE10",
"US912810QH41", "US912810SR05", "US912810QK79", "US912810SQ22",
"US912810QL52", "US912810ST60", "US912810QN19", "US912810QQ40",
"US912810QS06", "US912810QT88", "US912810QU51", "US912810QW18",
"US912810QX90", "US912810QY73", "US912810QZ49", "US912810RB61",
"US912810RC45", "US912810RD28", "US912810RE01", "US912810RG58",
"US912810RH32", "US912810RJ97", "US912810RK60", "US912810RM27",
"US912810RN00", "US912810RP57", "US912810RQ31", "US912810RS96",
"US912810RT79", "US912810RU43", "US912810RV26", "US912810RX81",
"US912810RY64", "US912810RZ30", "US912810SA79", "US912810SC36",
"US912810SD19", "US912810SE91", "US912810SF66", "US912810SH23",
"US912810SJ88", "US912810SK51", "US912810SL35", "US912810SN90",
"US912810SP49", "US912810SS87"), YrsToMat = c(1, 1, 1, 1, 1.08333333333333,
1.08333333333333, 1.08333333333333, 1.08333333333333, 1.16666666666667,
1.16666666666667, 1.16666666666667, 1.16666666666667, 1.16666666666667,
1.25, 1.25, 1.25, 1.25, 1.33333333333333, 1.33333333333333,
1.33333333333333,
1.33333333333333, 1.41666666666667, 1.41666666666667, 1.41666666666667,
1.41666666666667, 1.41666666666667, 1.5, 1.5, 1.5, 1.5, 1.58333333333333,
1.58333333333333, 1.58333333333333, 1.58333333333333, 1.66666666666667,
1.66666666666667, 1.66666666666667, 1.66666666666667, 1.66666666666667,
1.66666666666667, 1.75, 1.75, 1.75, 1.75, 1.83333333333333,
1.83333333333333,
1.83333333333333, 1.83333333333333, 1.91666666666667, 1.91666666666667,
1.91666666666667, 1.91666666666667, 1.91666666666667, 2, 2, 2,
2.08333333333333, 2.08333333333333, 2.16666666666667, 2.16666666666667,
2.16666666666667, 2.16666666666667, 2.16666666666667, 2.25, 2.25,
2.25, 2.33333333333333, 2.33333333333333, 2.33333333333333,
2.41666666666667,
2.41666666666667, 2.41666666666667, 2.41666666666667, 2.5, 2.5,
2.5, 2.58333333333333, 2.58333333333333, 2.58333333333333,
2.66666666666667,
2.66666666666667, 2.66666666666667, 2.66666666666667, 2.66666666666667,
2.75, 2.75, 2.75, 2.83333333333333, 2.83333333333333, 2.83333333333333,
2.91666666666667, 2.91666666666667, 2.91666666666667, 2.91666666666667,
3, 3, 3.08333333333333, 3.08333333333333, 3.16666666666667,
3.16666666666667,
3.16666666666667, 3.25, 3.25, 3.33333333333333, 3.41666666666667,
3.41666666666667, 3.41666666666667, 3.5, 3.58333333333333,
3.58333333333333,
3.66666666666667, 3.66666666666667, 3.66666666666667, 3.75, 3.75,
3.83333333333333, 3.83333333333333, 3.91666666666667, 3.91666666666667,
3.91666666666667, 3.91666666666667, 4, 4, 4.08333333333333,
4.08333333333333,
4.16666666666667, 4.16666666666667, 4.16666666666667, 4.16666666666667,
4.25, 4.25, 4.33333333333333, 4.33333333333333, 4.41666666666667,
4.41666666666667, 4.41666666666667, 4.5, 4.5, 4.58333333333333,
4.58333333333333, 4.66666666666667, 4.66666666666667, 4.66666666666667,
4.66666666666667, 4.75, 4.75, 4.83333333333333, 4.83333333333333,
4.91666666666667, 4.91666666666667, 4.91666666666667, 5, 5,
5.08333333333333,
5.16666666666667, 5.16666666666667, 5.16666666666667, 5.25,
5.33333333333333,
5.41666666666667, 5.41666666666667, 5.5, 5.58333333333333,
5.66666666666667,
5.66666666666667, 5.66666666666667, 5.75, 5.83333333333333,
5.91666666666667,
5.91666666666667, 5.91666666666667, 6, 6.08333333333333, 6.16666666666667,
6.16666666666667, 6.16666666666667, 6.25, 6.33333333333333,
6.41666666666667,
6.41666666666667, 6.5, 6.58333333333333, 6.66666666666667,
6.66666666666667,
6.66666666666667, 6.75, 6.83333333333333, 6.91666666666667,
6.91666666666667,
6.91666666666667, 7, 7.16666666666667, 7.41666666666667, 7.66666666666667,
7.66666666666667, 8, 8, 8.25, 8.25, 8.41666666666667, 8.66666666666667,
8.66666666666667, 9, 9.25, 9.41666666666667, 9.41666666666667,
9.66666666666667, 10, 10.25, 15.25, 16.25, 16.4166666666667,
17.25, 17.4166666666667, 18.25, 18.4166666666667, 18.75, 19,
19.25, 19.5, 19.5, 19.75, 19.75, 20, 20, 20.25, 20.5, 20.75,
21, 21.25, 21.5, 21.75, 22, 22.25, 22.5, 22.75, 23, 23.25, 23.5,
23.75, 24, 24.25, 24.5, 24.75, 25, 25.25, 25.5, 25.75, 26, 26.25,
26.5, 26.75, 27, 27.25, 27.5, 27.75, 28, 28.25, 28.5, 28.75,
29, 29.25, 29.5, 29.75, 30), Coupons = c(0.02625, 0.01875, 0.0175,
0.015, 0.025, 0.02125, 0.02, 0.01625, 0.025, 0.015, 0.02, 0.01875,
0.01375, 0.02375, 0.0175, 0.01875, 0.01125, 0.0225, 0.0175, 0.01875,
0.00375, 0.02125, 0.0175, 0.0175, 0.01875, 0.00125, 0.0175, 0.01875,
0.0175, 0.00125, 0.0175, 0.02125, 0.0175, 0.00125, 0.01875, 0.02,
0.00125, 0.0725, 0.01625, 0.015, 0.01625, 0.01875, 0.015, 0.00125,
0.01875, 0.0175, 0.01375, 0.00125, 0.07625, 0.02, 0.01875, 0.01625,
0.00125, 0.02, 0.01625, 0.00125, 0.02125, 0.015, 0.07125, 0.02375,
0.0175, 0.02, 0.01375, 0.02625, 0.015, 0.005, 0.025, 0.015, 0.0025,
0.0275, 0.01625, 0.0175, 0.00125, 0.0275, 0.01625, 0.0025, 0.02625,
0.01375, 0.00125, 0.0625, 0.0125, 0.025, 0.0275, 0.00125, 0.01375,
0.0275, 0.00125, 0.02875, 0.01375, 0.00125, 0.02875, 0.01625,
0.0275, 0.0025, 0.02875, 0.02125, 0.02625, 0.0225, 0.025, 0.0275,
0.0225, 0.02375, 0.02125, 0.02125, 0.0225, 0.025, 0.02, 0.02,
0.0175, 0.02, 0.02125, 0.02375, 0.0175, 0.01875, 0.0125, 0.02125,
0.015, 0.075, 0.0225, 0.0225, 0.015, 0.02125, 0.015, 0.0225,
0.0175, 0.07625, 0.025, 0.02, 0.01375, 0.0275, 0.01125, 0.02625,
0.005, 0.02875, 0.02125, 0.00375, 0.02875, 0.0025, 0.0275, 0.0025,
0.06875, 0.02, 0.02875, 0.0025, 0.0275, 0.0025, 0.03, 0.0025,
0.03, 0.0225, 0.0025, 0.02875, 0.00375, 0.02625, 0.06, 0.02625,
0.01625, 0.025, 0.0225, 0.02375, 0.01625, 0.02125, 0.01875, 0.0675,
0.015, 0.01875, 0.01375, 0.01625, 0.065, 0.02, 0.01625, 0.01625,
0.0175, 0.06625, 0.0225, 0.015, 0.01125, 0.00625, 0.02375, 0.005,
0.005, 0.005, 0.06375, 0.0225, 0.00375, 0.005, 0.00375, 0.06125,
0.0225, 0.005, 0.00625, 0.0275, 0.02875, 0.055, 0.02875, 0.0525,
0.03125, 0.0525, 0.02625, 0.02375, 0.06125, 0.01625, 0.0175,
0.015, 0.0625, 0.00625, 0.00625, 0.00875, 0.05375, 0.045, 0.0475,
0.05, 0.04375, 0.045, 0.035, 0.0425, 0.045, 0.04375, 0.04625,
0.04375, 0.01125, 0.03875, 0.01125, 0.0425, 0.01375, 0.0475,
0.04375, 0.0375, 0.03125, 0.03125, 0.03, 0.0275, 0.0275, 0.03125,
0.02875, 0.03625, 0.0375, 0.03625, 0.03375, 0.03125, 0.03, 0.025,
0.03, 0.02875, 0.03, 0.025, 0.025, 0.0225, 0.02875, 0.03, 0.03,
0.0275, 0.0275, 0.03, 0.03125, 0.03, 0.03375, 0.03, 0.02875,
0.0225, 0.02375, 0.02, 0.0125, 0.01375, 0.01625), Prices = c(102.5703125,
101.72265625, 101.6015625, 101.36328125, 102.6328125, 102.1328125,
102.00390625, 101.6015625, 102.84375, 101.57421875, 102.26171875,
102.0078125, 101.43359375, 102.85546875, 101.99609375, 102.16015625,
101.23046875, 102.875, 102.125, 102.2890625, 100.3046875, 102.859375,
102.31640625, 102.25390625, 102.4296875, 99.98046875, 102.44140625,
102.5703125, 102.3828125, 99.96484375, 102.5703125, 103.08984375,
102.50390625, 99.94921875, 102.84375, 103.0390625, 99.94140625,
111.8828125, 102.484375, 102.2734375, 102.53125, 102.96484375,
102.36328125, 99.93359375, 103.11328125, 102.89453125, 102.25,
99.93359375, 114.38671875, 103.48828125, 103.25, 102.8359375,
99.921875, 103.63671875, 102.94921875, 99.92578125, 104.046875,
102.8046875, 115.14453125, 104.73828125, 103.40234375, 103.98828125,
102.625, 105.46484375, 102.953125, 100.72265625, 105.375, 103.05859375,
100.15625, 106.16015625, 103.45703125, 103.8125, 99.84375, 106.359375,
103.56640625, 100.140625, 106.24609375, 103.0390625, 99.80859375,
116.2109375, 102.79296875, 106.203125, 106.77734375, 99.7890625,
103.21484375, 106.953125, 99.7734375, 107.515625, 103.30859375,
99.75390625, 107.734375, 104.12109375, 107.48046875, 100.109375,
107.93359375, 105.7109375, 107.37109375, 106.22265625, 107.15625,
108.03515625, 106.375, 106.8984375, 106.08984375, 106.21484375,
106.77734375, 107.69921875, 105.92578125, 106.04296875, 105.27734375,
106.17578125, 106.73046875, 107.73046875, 105.3671875, 105.921875,
103.58203125, 106.96875, 104.578125, 128.28515625, 107.56640625,
107.6484375, 104.65234375, 107.203125, 104.7109375, 107.83203125,
105.78515625, 130.33203125, 108.984375, 106.9375, 104.30078125,
110.16015625, 103.2890625, 109.78125, 100.63671875, 111.02734375,
107.7890625, 100.0703125, 111.18359375, 99.484375, 110.76953125,
99.42578125, 130.01171875, 107.5234375, 111.51171875, 99.375,
111.08203125, 99.34375, 112.43359375, 99.28515625, 112.59765625,
108.99609375, 99.24609375, 112.1484375, 99.8203125, 111.0625,
128.45703125, 111.1953125, 106.08984375, 110.65625, 109.44921875,
110.21875, 106.19921875, 108.94140625, 107.6328125, 135.08984375,
105.59375, 107.68359375, 104.87890625, 106.32421875, 134.97265625,
108.57421875, 106.34765625, 106.3828125, 107.1796875, 136.921875,
110.2734375, 105.66796875, 103.36328125, 100.21484375, 111.2734375,
99.3515625, 99.26953125, 99.2109375, 137.765625, 110.61328125,
98.3125, 99.03125, 98.10546875, 137.24609375, 110.81640625, 98.84765625,
99.640625, 114.51953125, 115.71875, 135.74609375, 116.0078125,
134.7265625, 118.25, 135.58984375, 114.6171875, 112.8125, 144.94140625,
106.765625, 107.9140625, 105.6328125, 149.1015625, 97.59375,
97.3515625, 99.578125, 143.74609375, 146.921875, 152.53125, 156.859375,
148.73046875, 151.16015625, 135.8828125, 148.4296875, 153.0390625,
151.30859375, 156, 151.97265625, 94.7109375, 143.29296875, 94.45703125,
150.3515625, 98.625, 159.8359375, 153.29296875, 141.94921875,
130.609375, 130.9140625, 128.421875, 123.734375, 123.625, 130.94921875,
126.12890625, 140.9765625, 143.6328125, 141.2890625, 136.44921875,
131.53125, 129.0390625, 118.79296875, 129.28125, 126.765625,
129.61328125, 119.00390625, 119.05078125, 113.7109375, 127.30078125,
130.30859375, 130.42578125, 124.89453125, 125.05859375, 130.81640625,
133.80859375, 131.1171875, 140.05859375, 131.4375, 128.640625,
114.03515625, 117.0703125, 108.23046875, 90.32421875, 93.21484375,
99.171875), Yields = c(0.1337081, 0.1362573, 0.133515, 0.1241131,
0.1399032, 0.1407489, 0.135751, 0.1350621, 0.1296603, 0.1416507,
0.1150397, 0.1425034, 0.1380301, 0.1442954, 0.1386738, 0.1313512,
0.1317766, 0.1415287, 0.1430796, 0.1440013, 0.1445889, 0.1504745,
0.1504191, 0.1478758, 0.1479262, 0.1388794, 0.1546924, 0.1494229,
0.150287, 0.1486016, 0.1576033, 0.1612303, 0.1586688, 0.1572704,
0.1592381, 0.1662562, 0.1603484, 0.2453876, 0.1618873, 0.1611249,
0.1677527, 0.1681253, 0.1709984, 0.1632234, 0.1649997, 0.1602392,
0.1664094, 0.1614686, 0.2275633, 0.1688146, 0.1688992, 0.1678715,
0.1660078, 0.1702386, 0.1710206, 0.1623381, 0.1713865, 0.1720528,
0.2235201, 0.1764782, 0.1714474, 0.1834972, 0.1794814, 0.1796261,
0.1785715, 0.1824745, 0.1813703, 0.1806178, 0.1837643, 0.1857355,
0.1859493, 0.1896815, 0.1889451, 0.1905526, 0.1896534, 0.194313,
0.1931176, 0.1917809, 0.198368, 0.2264378, 0.1968473, 0.1961992,
0.1945467, 0.2033451, 0.1980432, 0.2042049, 0.2067191, 0.2047044,
0.1995581, 0.2111883, 0.2066671, 0.2033169, 0.2054688, 0.212789,
0.2132956, 0.2091312, 0.2193078, 0.2191277, 0.2261665, 0.2291516,
0.2244644, 0.2365864, 0.2372155, 0.2465419, 0.2519977, 0.2571519,
0.2530085, 0.2603545, 0.2662295, 0.2637156, 0.275636, 0.2741968,
0.2752424, 0.2822191, 0.286467, 0.2911749, 0.2951612, 0.2928947,
0.301369, 0.3008203, 0.3018345, 0.307993, 0.3115587, 0.3146542,
0.3202659, 0.3459327, 0.3240707, 0.335542, 0.3331675, 0.3348024,
0.3429906, 0.3441309, 0.3514909, 0.3521024, 0.359143, 0.3589054,
0.3626047, 0.3658439, 0.3741231, 0.3766819, 0.4207583, 0.3835824,
0.3804697, 0.3854424, 0.3882631, 0.3898512, 0.395374, 0.3997549,
0.4054119, 0.412211, 0.4052657, 0.4135729, 0.4114041, 0.4200256,
0.4569543, 0.4290136, 0.4393644, 0.4406205, 0.4517372, 0.4599254,
0.4715513, 0.4736518, 0.4858387, 0.4992027, 0.5034059, 0.4966529,
0.511404, 0.5211256, 0.5228673, 0.5340614, 0.5322963, 0.5409351,
0.5469844, 0.5586764, 0.5618671, 0.5625578, 0.5754976, 0.5903231,
0.5911177, 0.6032908, 0.6149554, 0.6226418, 0.6137462, 0.6299625,
0.6341457, 0.6470986, 0.65936, 0.6378036, 0.6554544, 0.6709587,
0.677713, 0.6803971, 0.7054962, 0.7199359, 0.7332262, 0.7434956,
0.7554881, 0.7644571, 0.7813789, 0.8036422, 0.7739499, 0.8178105,
0.8306454, 0.8618547, 0.8354958, 0.8910527, 0.9108458, 0.9194552,
0.8813713, 1.1314021, 1.1783204, 1.1851732, 1.2244673, 1.2326062,
1.2828189, 1.2913256, 1.2968105, 1.3089486, 1.3151415, 1.3324039,
1.437676, 1.3619944, 1.4494158, 1.359794, 1.4546407, 1.3542914,
1.3762002, 1.4069981, 1.4291268, 1.4295199, 1.4529993, 1.4687229,
1.4848191, 1.4836052, 1.4998736, 1.490619, 1.4965878, 1.5089954,
1.5211415, 1.5331939, 1.5447829, 1.5641817, 1.5556365, 1.564367,
1.5622115, 1.5825676, 1.5871687, 1.5973929, 1.5873149, 1.5821889,
1.5869259, 1.6005552, 1.6014668, 1.5984828, 1.5985781, 1.6041773,
1.593257, 1.608535, 1.6153224, 1.6352791, 1.6326895, 1.6439244,
1.6671026, 1.6658406, 1.6601911)), row.names = c(NA, -265L), class =
"data.frame")
|