我正在使用该软件包YieldCurve
来获取Nelson Siegel参数。
标准示例:
library("YieldCurve")
data(FedYieldCurve)
maturity.Fed <- c(3/12, 0.5, 1, 2, 3, 5, 7, 10)
NSParameters <- Nelson.Siegel(rate=first(FedYieldCurve, '10 month'),
maturity=maturity.Fed)
例如,如何获取参数的标准误差beta_0
?
您可以引导标准错误。根据交叉验证的相关文章,时间序列的适当方法是块引导。
一种可能是使用,boot::tsboot
但可能会有更好的方法(即应用重叠或考虑平稳性)。
预先细分时间序列。
tt <- first(FedYieldCurve, '10 month')
到目前为止,这是您得到的:
Nelson.Siegel(rate=first(FedYieldCurve, '10 month'),
maturity=maturity.Fed)$beta_0
# beta_0
# 1982-01-01 14.34594
# 1982-02-01 14.14681
# 1982-03-01 13.61065
# 1982-04-01 13.61517
# 1982-05-01 13.52630
# 1982-06-01 14.13378
# 1982-07-01 13.84696
# 1982-08-01 13.02162
# 1982-09-01 12.10749
# 1982-10-01 11.02616
这是引导程序:
library(boot)
FUN <- function(tt) Nelson.Siegel(rate=tt, maturity=maturity.Fed)$beta_0
set.seed(42)
res <- tsboot(tt, FUN, R=999, l=4, sim="fixed")
res
# BLOCK BOOTSTRAP FOR TIME SERIES
#
# Fixed Block Length of 4
#
# Call:
# tsboot(tseries = tt, statistic = FUN, R = 999, l = 4, sim = "fixed")
#
#
# Bootstrap Statistics :
# original bias std. error
# 1982-01-01 14.34594 -0.13196802 0.2612880
# 1982-02-01 14.14681 -0.11939397 0.2973519
# 1982-03-01 13.61065 0.21889530 0.2847908
# 1982-04-01 13.61517 0.13024656 0.2722655
# 1982-05-01 13.52630 0.14400794 0.3407014
# 1982-06-01 14.13378 -0.53877853 0.4418189
# 1982-07-01 13.84696 -0.45311547 0.6637142
# 1982-08-01 13.02162 0.03079636 0.8099144
# 1982-09-01 12.10749 0.25592742 1.0325852
# 1982-10-01 11.02616 0.54346793 0.9569845
注意:如果您不希望此代码永久运行,则可以将复制减少到R=99
进行测试。
您可能需要按照链接的“交叉验证”文章的两个答案中给出的信息,更详细地研究块引导程序。例如,我无法告诉您正确的块长度(l=
参数)是多少。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句