knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(dplyr)
library(ggplot2)
library(canbank)

The package gives access ot the Bank of Canada data API. Currently there are r scales::comma(nrow(list_boc_series())) data series available, grouped into r scales::comma(nrow(list_boc_series_groups())). We obtain basic information for the series or series groups.

series_list <- list_boc_series()
series_group_list <- list_boc_series_groups()

head(series_list) %>% knitr::kable()

Data discovery is still somewhat cumbersome, we can search for phrases in the labels or description.

series_list %>%
  filter(grepl("home",label,ignore.case = TRUE)) %>% 
  select(-link) %>%
  knitr::kable()

If we are intersted in MLS home price index, we might want to inspect the series group FSHUB_20210317_C2.

get_boc_series_group("FSHUB_20210317_C2") %>%
  mutate(name=gsub(" \\(.+\\)$","",label)) %>%
  ggplot(aes(x=Date,y=Value)) +
  geom_line(colour="steelblue",size=1) +
  geom_smooth(se=FALSE,method="lm",formula=y~1,colour="brown",size=0.5) +
  facet_wrap(~name,scales="free_y",ncol=1) +
  labs(title="MLS overview data for Canada with long-run averages",
       x=NULL,y=NULL,
       caption="Source: Bank of Canada series group FSHUB_20210317_C2")

Or we might be interested in 5-year mortgage rates.

mortgate_rate_series <- list_boc_series() %>% 
  filter(grepl("mortgage rate",label)) 

mortgate_rate_series %>%
  select(-link) %>%
  knitr::kable()

Taking a closer look at the 5-year fixed and estimated variable rates.

get_boc_series(c("BROKER_AVERAGE_5YR_VRM","WM_SAN_FEUN20181109_C1_5Y-MR")) %>%
  ggplot(aes(x=Date,y=Value/100,colour=label)) +
  geom_line() +
  scale_y_continuous(labels=scales::percent) +
  theme(legend.position = "bottom") +
  labs(title="Mortgage rates",
       x=NULL,y=NULL, colour=NULL,
       caption="Source: Bank of Canada series BROKER_AVERAGE_5YR_VRM, WM_SAN_FEUN20181109_C1_5Y-MR")


mountainMath/canbank documentation built on March 12, 2024, 1:22 a.m.