BIS

Stefan Angrick

2025-01-02

The BIS package provides an R interface to data hosted by the Bank for International Settlements, specifically the single-file data sets available on the BIS homepage.

Installing the package

You can install the package from CRAN or GitHub.

library(devtools)
install_github("stefanangrick/BIS")  # GitHub
install.packages("BIS")              # CRAN

Example usage

To start using the package, load it into your R session.

library("BIS")

Next, retrieve a list of available data sets using the get_datasets() function.

ds <- get_datasets()
head(ds, 20)

The get_datasets() function returns a tibble data frame listing available data sets. Use the url column as input for the get_bis() function to download, parse, and import the corresponding data set.

For example, to import monthly-frequency data on central banks’ policy rates, use the following code:

rates <- get_bis(ds$url[ds$id == "WS_CBPOL_csv_flat"])
head(rates)

To plot the data with ggplot2, run the following:

library("dplyr")
library("ggplot2")
library("zoo")

rates_plot <- subset(rates, ref_area %in% c("US", "XM", "JP", "GB", "CH", "CA"))
rates_plot <- subset(rates, ref_area %in% c("US: United States",
                                            "XM: Euro area",
                                            "JP: Japan",
                                            "GB: United Kingdom",
                                            "CH: Switzerland",
                                            "CA: Canada"))
rates_plot <- mutate(rates_plot, time_period =
                       as.Date(as.yearmon(time_period, format = "%Y-%m")))

ggplot(rates_plot, aes(time_period, obs_value, color = ref_area)) +
  geom_line(show.legend = FALSE) +
  facet_wrap(~ref_area) +
  labs(title = "Central bank policy rates",
       subtitle = "% per annum", x = NULL, y = NULL)

Note that BIS data sets use various time formats. The zoo package (e.g., as.yearmon()) can handle most of these formats.

Reading locally stored files

In some cases, the BIS homepage may only be accessible through a web browser, preventing the programmatic retrieval of data sets directly within R. When this occurs, users can manually download the files and use the read_bis() function to parse them.

To read a locally stored CSV file, use the following code:

df <- read_bis("WS_CBPOL_csv_flat.csv")

To read a locally stored ZIP file, use this code:

df <- read_bis(.unzip_file("WS_CBPOL_csv_flat.zip"))

Retrieving individual data series

To retrieve individual data series instead of full data sets, consider using the BIS SDMX RESTful API. The rsdmx R package supports processing SDMX data in R. The latest development version of rsdmx includes a BIS connector to streamline the process.

Note

This package is neither officially related to nor endorsed by the Bank for International Settlements. It is based on a fork of CC0-licensed code by expersso. Please avoid overloading the BIS servers with unnecessary requests.