This R package usfrbcp
provides functions for processing the US Federal Reserve Bank's commercial paper history data. The main function posts a query to the US Federal Reserve Bank's web site. By default the download includes commercial paper rates, volumes, and outstanding issue counts, variously in daily, weekly, or monthly frequency. The download data from the service is in compressed XML format. The query function transforms that data into a list of products. Several supporting functions then convert these lists by data type into smaller lists of data frames for convenient usage. The data frames can be used as-is or converted easily to a time series format such as xts
.
The main function retrieves the commercial paper data history archive from the web service and extracts it into a collection of lists:
require(usfrbcp)
cp <- getCommercialPaper()
summary(cp)
We then decompose this into the products of interest, such as
rates <- getCommercialPaperRates(cp,"text")
summary(rates)
volumes <- getCommercialPaperVolumes(cp,"text")
summary(volumes)
The data frame might be converted to xts
and plotted for example with lattice
:
require(xts)
require(lattice)
df <- mergeSeries(rates)
xt = xts(df,order.by=as.Date(rownames(df)))
xyplot.ts(xt,scales=list(y=list(relation="same")),ylab="Rate (%)")
xyplot.ts(xt,superpose=TRUE,auto.key=list(columns=4),ylab="Yield (%)")
One might also plot data from the volume series, which also contains dollar values:
volumes <- getCommercialPaperVolumes(cp,"text")
v = volumes[[35]]
xyplot.ts(na.omit(xts(v$df,order.by=as.Date(rownames(v$df)))),
ylab=paste(v$unit,v$currency,v$unit_mult),
panel=function(x,...){
panel.xyplot(x,...)
panel.grid(-1,0)
panel.loess(x,col=2,...)},
main=v$short_desc)
Using dplyr
and tidyr
we can easily create some ggplot2
graphics. Using the year-end series as an example:
require(ggplot2)
require(dplyr)
require(tidyr)
require(scales)
rv = getCommercialPaperYearend(cp,"text")
df <- mergeSeries(rv)
df <- df %>%
mutate(Date=as.Date(rownames(df))) %>%
gather(Product,Outstanding,starts_with("DT"))
# p <- ggplot(df,aes(x=Date,y=Outstanding,group=Product))
# p + geom_line(aes(colour=Product)) + scale_x_date()
p <- ggplot(df,aes(x=Date,y=Outstanding))
p + geom_line(aes(colour=Product)) +
facet_wrap(~Product,ncol=2,scales="fixed") +
scale_x_date(limits=c(as.Date("2010-1-1"),max(df$Date))) +
theme(legend.position="none") +
ggtitle("Commercial Paper Outstanding Year End")
RATES is data set with 24 Series:
VOL is data set with 60 Series
OUTST is data set with 77 Series
OUTST_YREND is data set with 4 Series
OUTST_OLD is data set with 25 Series
RATES_OLD is data set with 12 Series
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.