Created
June 30, 2017 11:48
-
-
Save vikjam/14e5ea9d36f04dcb7cd267a6a50fe4a0 to your computer and use it in GitHub Desktop.
Plot of yields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(rvest) | |
| library(ggplot2) | |
| library(ggthemes) | |
| library(MASS) | |
| library(splines) | |
| treas.html <- html("http://www.treasury.gov/resource-center/data-chart-center/interest-rates/Pages/TextView.aspx?data=yield") | |
| yield.data <- treas.html %>% | |
| html_nodes("table") %>% | |
| .[[67]] %>% | |
| html_table(fill = TRUE) | |
| treas.plot <- data.frame(end = c(1/12, 3/12, 6/12, 1, 2, 3, 5, 7, 10, 20, 30), | |
| rate = as.vector(t(yield.data[ 10, 2:ncol(yield.data)]))) | |
| treas.gg <- ggplot(aes(x = end, y = rate), data = treas.plot) | |
| treas.curve <- treas.gg + geom_point() + | |
| geom_smooth(se = FALSE, | |
| method = "lm", | |
| formula = y ~ ns(x, 3), | |
| colour = "black") + | |
| theme_tufte(base_size = 15) + | |
| xlab("Maturity (years)") + | |
| ylab("Yield (%)") | |
| ggsave(file = "treas-curve.svg") | |
| greek.html <- html("http://www.bankofgreece.gr/Pages/en/Statistics/rates_markets/titloieldimosiou/titloieldimosiou.aspx") | |
| greek.data <- greek.html %>% | |
| html_nodes("table") %>% | |
| html_nodes("table") %>% | |
| .[[268]] %>% | |
| html_table(fill = TRUE) | |
| greek.plot <- data.frame(end = c(3, 5, 10, 15, 20, 30), | |
| rate = as.vector(t(greek.data[1, seq(3, ncol(greek.data), by = 2)]))) | |
| greek.gg <- ggplot(aes(x = end, y = rate), data = greek.plot) | |
| greek.curve <- greek.gg + geom_point() + | |
| geom_smooth(se = FALSE, | |
| method = "lm", | |
| formula = y ~ ns(x, 3), | |
| colour = "black") + | |
| theme_tufte(base_size = 15) + | |
| xlab("Maturity (years)") + | |
| ylab("Yield (%)") | |
| ggsave(file = "greek-curve.svg") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment