我已经能够获得Nelson-Siegel参数,但我想使用这些参数来适应xts对象中的多个日期。我的示例参数数据如下所示:
beta_0 beta_1 beta_2 lambda
2016-05-09 1.242251 -1.587428 -2.877986 0.3260436
2016-05-10 1.310086 -1.698266 -2.771920 0.2988770
2016-05-11 1.305433 -1.709373 -2.741923 0.2988770
2016-05-12 1.296316 -1.647487 -2.917838 0.3260436
2016-05-13 1.296014 -1.703771 -2.716187 0.2988770
和成熟度数据:
DBR 4 1/4 07/04/17 OBL 0 1/2 10/13/17 DBR 4 01/04/18 OBL 0 1/2 02/23/18 OBL 0 1/4 04/13/18
2016-05-09 1.153425 1.430137 1.657534 1.794521 1.928767
2016-05-10 1.150685 1.427397 1.654795 1.791781 1.926027
2016-05-11 1.147945 1.424658 1.652055 1.789041 1.923288
2016-05-12 1.145205 1.421918 1.649315 1.786301 1.920548
2016-05-13 1.142466 1.419178 1.646575 1.783562 1.917808
包YieldCurve有一个很好的函数NSrates
,它会根据参数和期限来计算Nelson-Siegel的收益率,但我只能指出它当时为1行的位置。
> NSrates(para[1,], matu[1,])
X1.15342465753425 X1.43013698630137 X1.65753424657534 X1.79452054794521 X1.92876712328767
2016-05-09 -0.5036755 -0.5212248 -0.5310275 -0.5351072 -0.5378716
因此前两行的最终结果如下所示。什么是最好的方法来做到这一点,而不必多天(在我的情况下500)?
rbind(NSrates(para[1,], matu[1,]), NSrates(para[2,], matu[2,]))
X1.15342465753425 X1.43013698630137 X1.65753424657534 X1.79452054794521 X1.92876712328767
2016-05-09 -0.5036755 -0.5212248 -0.5310275 -0.5351072 -0.5378716
2016-05-10 -0.5071923 -0.5195874 -0.5260411 -0.5284441 -0.5297903
这是数据:
> dput(para)
structure(c(1.24225078418646, 1.31008637078059, 1.30543299665979,
1.29631631535762, 1.29601365243175, -1.58742842487855, -1.69826559638279,
-1.7093729214809, -1.64748723193503, -1.7037710977632, -2.87798606181918,
-2.77191996754914, -2.74192263452223, -2.917838377094, -2.71618708784827,
0.326043563651773, 0.298877004832293, 0.298877004832293, 0.326043563651773,
0.298877004832293), .indexCLASS = "Date", .indexTZ = "UTC", tclass = "Date", tzone = "UTC", class = c("xts",
"zoo"), na.action = structure(1:34, class = "omit", index = c(978307200,
978393600, 978480000, 978566400, 978652800, 978912000, 978998400,
979084800, 979171200, 979257600, 979516800, 979603200, 979689600,
979776000, 979862400, 980121600, 980208000, 980294400, 980380800,
980467200, 980726400, 980812800, 980899200, 980985600, 981072000,
981331200, 981417600, 981504000, 981590400, 981676800, 981936000,
982022400, 982108800, 982195200)), index = structure(c(1462752000,
1462838400, 1462924800, 1463011200, 1463097600), tzone = "UTC", tclass = "Date"), .Dim = c(5L,
4L), .Dimnames = list(NULL, c("beta_0", "beta_1", "beta_2", "lambda"
)))
> dput(matu)
structure(c(1.15342465753425, 1.15068493150685, 1.14794520547945,
1.14520547945205, 1.14246575342466, 1.43013698630137, 1.42739726027397,
1.42465753424658, 1.42191780821918, 1.41917808219178, 1.65753424657534,
1.65479452054795, 1.65205479452055, 1.64931506849315, 1.64657534246575,
1.79452054794521, 1.79178082191781, 1.78904109589041, 1.78630136986301,
1.78356164383562, 1.92876712328767, 1.92602739726027, 1.92328767123288,
1.92054794520548, 1.91780821917808), .indexCLASS = "Date", .indexTZ = "UTC", tclass = "Date", tzone = "UTC", class = c("xts",
"zoo"), index = structure(c(1462752000, 1462838400, 1462924800,
1463011200, 1463097600), tzone = "UTC", tclass = "Date"), .Dim = c(5L,
5L), .Dimnames = list(NULL, c("DBR 4 1/4 07/04/17", "OBL 0 1/2 10/13/17",
"DBR 4 01/04/18", "OBL 0 1/2 02/23/18", "OBL 0 1/4 04/13/18")))