I am looking for a standardized method for arranging data in relative time. Applications include accounting data such as FY1,FY2,etc... and economic data such as the term structure of interest rates using the 1 year, 2 year, 3 year, etc...
I would like to be able to compare a set of time series data that is current and several historic time series sets that represent similar situations or historic norms. I was looking at xts but it looks like I need to use an absolute time reference.
I would eventually like to use Quantmod's charting functions or graphs with equivalent capability to visualize the data. Since chartSeries requires a time series object, does anyone know how to do this? Even a point in the right direction would be helpful. Thanks.
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)
Problem: I would like to be able to select a time period such as September of 2007 and grab each daily yield curve to plot against the current yield curve. I'm sure I could use several pages of first and last functions but that would be more work than building it in Excel.