FOMC Dates – Price Data Exploration

December 14, 2014

(This article was first published on Return and Risk, and kindly contributed to R-bloggers)

As a first step in visualizing/exploring the data from my last post, FOMC Dates – Scraping Data From Web Pages, I’ll plot the FOMC announcement dates along with the following price series: 2-Year and 10-Year US Treasury yields, S&P500 ETF (SPY) and USD Index ETF (UUP).

I’ll use the quantmod R package to download the price data from the US Federal Reserve Economic Data (FRED) database and Yahoo Finance.

For the graphics, I like the cool gglot2 R package, and although it’s more complicated to code, it’s worth it.

First, install and load the quantmod, reshape2 and ggplot2 R packages.

install.packages(c("quantmod", "reshape2", "ggplot2"), repos = 

Download the price series data and store as xts objects, and load the FOMC announcement dates from the file saved in the last post.

# get 2-year and 10-year US Treasury yields
getSymbols(c("DGS2", "DGS10"), src = "FRED")
DGS2 <- DGS2["2009-01-02/"]
DGS10 <- DGS10["2009-01-02/"]
# get S&P500 ETF prices
getSymbols("SPY", from = "2009-01-02")
# get USD Index ETF prices
getSymbols("UUP", from = "2009-01-02")
# load FOMC announcement dates from file previously saved in working directory

Reshape the yield data in order to plot both the 2-Year and 10-Year yields on the same chart. The FOMC announcement dates will be shown as dashed vertical lines.

# prepare yield data
yields <- data.frame(index(DGS2), DGS2, DGS10)
names(yields) <- c("Date", "2Yr Yield", "10Yr Yield")
yieldsmelt <- melt(yields, id.vars = "Date")
# plot yield chart
gp <- ggplot(yieldsmelt, aes(x = Date, y = value)) +
geom_line(aes(colour = variable)) +
labs(list(title = "US Treasury Yields with FOMC Dates", x = "",
y = "% p.a.")) +
scale_colour_manual(name = "Yield", values = c("darkblue", "darkred")) +
geom_vline(xintercept = as.numeric(fomcdates), linetype = "dashed",
size = 0.5, alpha = 0.5) +

Finally, plot the charts for the S&P500 and USD Index ETFs – no need to prep the data as we’re plotting 1 time series per chart.

# plot S&P500 chart
gp1 <- autoplot.zoo(SPY[, "SPY.Adjusted"]) +
labs(list(title = "S&P500 ETF (SPY) with FOMC Dates", x = "",
y = "USD")) +
geom_line(colour = "darkblue") +
geom_vline(xintercept = as.numeric(fomcdates), linetype = "dashed",
size = 0.5, alpha = 0.5) +

# plot USD Index chart
gp2 <- autoplot.zoo(UUP[, "UUP.Adjusted"]) +
labs(list(title = "USD Index ETF (UUP) with FOMC Dates", x = "",
y = "USD")) +
geom_line(colour = "darkblue") +
geom_vline(xintercept = as.numeric(fomcdates), linetype = "dashed",
size = 0.5, alpha = 0.5) +

All look OK but a lot more exploring to do…

Click here for the R code on GitHub.

To leave a comment for the author, please follow the link and comment on their blog: Return and Risk. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)