我正在寻找一种在相对时间安排数据的标准化方法。应用包括FY1、FY2等会计数据……以及使用1年、2年、3年等利率期限结构等经济数据……
我希望能够比较一组当前的时间序列数据和代表类似情况或历史规范的几个历史时间序列集。我在看 xts 但看起来我需要使用绝对时间参考。
我最终想使用 Quantmod 的图表函数或具有同等能力的图表来可视化数据。由于 chartSeries 需要一个时间序列对象,有谁知道如何做到这一点?即使是正确方向的一点也会有所帮助。谢谢。
require(quantmod)
symbols=c("DGS1","DGS2","DGS3","DGS5","DGS7","DGS10","DGS20")
getSymbols(symbols,src="FRED")
one.h=mean(na.omit(DGS1));two.h=mean(na.omit(DGS2));three.h=mean(na.omit(DGS3));five.h=mean(na.omit(DGS5));seven.h=mean(na.omit(DGS7));ten.h=mean(na.omit(DGS10));twenty.h=mean(na.omit(DGS20))
historic=c(one.h,two.h,three.h,five.h,seven.h,ten.h,twenty.h)
current=c(last(DGS1),last(DGS2),last(DGS3),last(DGS5),last(DGS7),last(DGS10),last(DGS20))
years=c(1,2,3,5,7,10,20)
plot(years,current,type="o",pch=20,ann=FALSE)
lines(years,historic,type="o",pch=20,col="red",lty=3)
title(main="Term Structure of Interest Rates",col.main="red", font.main=4)
title(xlab="Years to Maturity",ylab="Interest Rate",col.lab=rgb(0,0.5,0))
legend(3, c("Current","Historic"),cex=0.8,col=c("black","red"),pch=20)
问题:我希望能够选择一个时间段,例如 2007 年 9 月,并抓取每条每日收益率曲线以绘制当前收益率曲线。我确定我可以使用几页的 first 和 last 函数,但这比在 Excel 中构建它更有效。