knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
An interface to structure the information provided by the Brazilian Central Bank. This package interfaces the Brazilian Central Bank web services to provide data already formatted into R's data structures.
From CRAN:
install.packages("rbcb")
From github using remotes:
remotes::install_github('wilsonfreitas/rbcb')
Load the package:
library(rbcb)
get_series
function
Download the series by calling rbcb::get_series
and pass the time series code is as the first argument.
For example, let's download the USDBRL time series which code is 1
.
rbcb::get_series(c(USDBRL = 1))
Note that this series starts at 1984 and has approximately 8000 rows.
Also note that you can name the downloaded series by passing a named vector
in the code
argument.
To download recent values you should use the argument last = N
, see below.
rbcb::get_series(c(USDBRL = 1), last = 10)
The series can be downloaded in many different types: tibble
, xts
, ts
or data.frame
, but the default is tibble
.
See the next example where the Brazilian Broad Consumer Price Index (IPCA) is downloaded as xts
object.
rbcb::get_series(c(IPCA = 433), last = 12, as = "xts")
or as a ts
object.
rbcb::get_series(c(IPCA = 433), last = 12, as = "ts")
Multiple series can be downloaded at once by passing a named vector with the series codes. The return is a named list with the downloaded series.
rbcb::get_series(c(IPCA = 433, IGPM = 189), last = 12, as = "ts")
The function get_market_expectations
returns market expectations discussed in the Focus Report that summarizes the statistics calculated from expectations collected from market practitioners.
The first argument type
accepts the following values:
annual
: annual expectationsquarterly
: quarterly expectationsmonthly
: monthly expectationstop5s-monthly
: monthly expectations for top 5 indicatorstop5s-annual
: annual expectations for top 5 indicatorsinflation-12-months
: inflation expectations for the next 12 monthsinstitutions
: market expectations informed by financial institutionsThe example below shows how to download IPCA's monthly expectations.
rbcb::get_market_expectations("monthly", "IPCA", end_date = "2018-01-31", `$top` = 5)
Use currency functions to download currency rates from the BCB OLINDA API.
olinda_list_currencies()
Use olinda_get_currency
function to download data from specific currency by
the currency symbol.
olinda_get_currency("USD", "2017-03-01", "2017-03-03")
The rates come quoted in BRL, so 3.10 is worth 1 USD in BRL.
Parity values
Type A currencies have parity values quoted in USD (1 CURRENCY in USD).
olinda_get_currency("CAD", "2017-03-01", "2017-03-01")
olinda_get_currency("CAD", "2017-03-01", "2017-03-01", parity = TRUE)
Type B currencies have parity values as 1 USD in CURRENCY, see AUD, for example.
olinda_get_currency("AUD", "2017-03-01", "2017-03-01")
olinda_get_currency("AUD", "2017-03-01", "2017-03-01", parity = TRUE)
Use currency functions to download currency rates from the BCB web site.
rbcb::get_currency("USD", "2017-03-01", "2017-03-10")
The rates come quoted in BRL, so 3.0970 is worth 1 USD in BRL.
All currency time series have an attribute called symbol
that stores its own
currency name.
attr(rbcb::get_currency("USD", "2017-03-01", "2017-03-10"), "symbol")
Trying another currency.
get_currency("JPY", "2017-03-01", "2017-03-10") |> Ask()
To see the avaliable currencies call list_currencies
.
rbcb::list_currencies()
There are 216 currencies available.
The API provides a matrix with the relations between exchange rates, this is the matrix of cross currency rates. This is a square matrix with the all exchange rates between all currencies.
x <- rbcb::get_currency_cross_rates("2017-03-10") dim(x)
# Since there are many currencies it is interesting to subset the matrix. cr <- c("USD", "BRL", "EUR", "CAD") x[cr, cr]
The rates are quoted by its columns labels, so the numbers in the BRL column are worth one currency unit in BRL.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.