# R中的收益率曲线排序

``````data(FedYieldCurve)
``````

``````            R_3M  R_6M  R_1Y  R_2Y  R_3Y  R_5Y  R_7Y R_10Y
1981-12-31 12.92 13.90 14.32 14.57 14.64 14.65 14.67 14.59
1982-01-31 14.28 14.81 14.73 14.82 14.73 14.54 14.46 14.43
1982-02-28 13.31 13.83 13.95 14.19 14.13 13.98 13.93 13.86
1982-03-31 13.34 13.87 13.98 14.20 14.18 14.00 13.94 13.87
1982-04-30 12.71 13.13 13.34 13.78 13.77 13.75 13.74 13.62
1982-05-31 13.08 13.76 14.07 14.47 14.48 14.43 14.47 14.30
``````

``````for (i in 1:ncol(FedYieldCurve))
{
normal <- sort(FedYieldCurve)
inverse<- sort(FedYieldCurve)
humped<- (FedYieldCurve-normal-inverse)
list <- rbind(normal, inverse, humped)
}
``````

``````d_diff <- t(apply(FedYieldCurve, 1, diff)) #difference in yield by maturity
incr <- apply(d_diff, 1, function(x) all(x > 0, na.rm=TRUE)) #all increasing yield
decr <- apply(d_diff, 1, function(x) all(x < 0, na.rm=TRUE)) #all decreasing yield

normal <-FedYieldCurve[incr,]
inverse <-FedYieldCurve[decr,]
humped <-FedYieldCurve[!incr&!decr,]# not incr and not decr
``````

0条评论