knitr::opts_chunk$set( message = FALSE, warning = FALSE, collapse = TRUE, fig.width = 6, fig.height = 4 )
The BIS
package package provides an R
interface to data hosted by the Bank
for International Settlements.
The package can be installed from either CRAN or Github.
library(devtools) install_github("expersso/BIS") # Github install.packages("BIS") # CRAN
The get_datasets
downloads a list of available datasets.
library(BIS) datasets <- get_datasets() head(datasets, 20)
The function get_bis
takes a url as input and downloads and parses the
corresponding CSV file from the BIS website. This automatic parsing of the data
is the major contribution of this package, since the different CSVs follow
different formats.
The following code loads monthly data on central banks' policy rates:
rates <- get_bis(datasets$url[datasets$name == "Policy rates (monthly)"], quiet = TRUE) head(rates)
We plot these data for a subset of countries.
library(dplyr) library(ggplot2) library(zoo) rates_plot <- rates %>% mutate(date = as.Date(as.yearmon(date))) %>% filter(grepl("^(XM|US|CH|JP|GB|CA)", ref_area)) ggplot(rates_plot, aes(date, obs_value, color = reference_area)) + geom_hline(yintercept = 0, linetype = "dashed", color = "grey70", size = 0.02) + geom_line(show.legend = FALSE) + facet_wrap(~reference_area) + theme_light() + theme(panel.grid = element_blank()) + labs(x = NULL, y = NULL, title = "Central bank policy rates", subtitle = "% per annum")
Note that the BIS data sets come with a number of different time formats, so
it's up to the user to parse these for himself/herself. The zoo
package
(especially as.yearqtr
and as.yearmon
) should take care of most cases.
Please also note that some datasets are fairly large (especially the first three
returned by get_datasets
), so you may need to run 64-bit R in order to load
all the data into memory.
Finally, please don't abuse BIS's servers with unnecessary calls.
This package is in no way officially related to, or endorsed by, the BIS.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.