FOMC Dates – Price Data Exploration

[This article was first published on Return and Risk, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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 = <br />    "http://cran.us.r-project.org")<br />library(quantmod)<br />library(reshape2)<br />library(ggplot2)

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<br />getSymbols(c("DGS2", "DGS10"), src = "FRED")<br />DGS2 <- DGS2["2009-01-02/"]<br />DGS10 <- DGS10["2009-01-02/"]<br /># get S&P500 ETF prices<br />getSymbols("SPY", from = "2009-01-02")<br /># get USD Index ETF prices<br />getSymbols("UUP", from = "2009-01-02")<br /># load FOMC announcement dates from file previously saved in working directory<br />load("fomcdates.RData")

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

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<br />gp1 <- autoplot.zoo(SPY[, "SPY.Adjusted"]) + <br />    labs(list(title = "S&P500 ETF (SPY) with FOMC Dates", x = "",<br />        y = "USD")) + <br />    geom_line(colour = "darkblue") + <br />    geom_vline(xintercept = as.numeric(fomcdates), linetype = "dashed", <br />        size = 0.5, alpha = 0.5) +<br />    scale_x_date()<br />print(gp1)
# plot USD Index chart<br />gp2 <- autoplot.zoo(UUP[, "UUP.Adjusted"]) + <br />    labs(list(title = "USD Index ETF (UUP) with FOMC Dates", x = "",<br />        y = "USD")) + <br />    geom_line(colour = "darkblue") +<br />    geom_vline(xintercept = as.numeric(fomcdates), linetype = "dashed", <br />        size = 0.5, alpha = 0.5) +<br />    scale_x_date()<br />print(gp2)

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.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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)