Type: | Package |
Title: | R Interface to Brazilian Central Bank Web Services |
Version: | 0.1.14 |
Author: | Wilson Freitas <wilson.freitas@gmail.com> |
Maintainer: | Wilson Freitas <wilson.freitas@gmail.com> |
Description: | The Brazilian Central Bank API delivers many datasets which regard economic activity, regional economy, international economy, public finances, credit indicators and many more. For more information please see http://dadosabertos.bcb.gov.br/. These datasets can be accessed through 'rbcb' functions and can be obtained in different data structures common to R ('tibble', 'data.frame', 'xts', ...). |
URL: | https://github.com/wilsonfreitas/rbcb, https://wilsonfreitas.github.io/rbcb/ |
BugReports: | https://github.com/wilsonfreitas/rbcb/issues |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
Imports: | httr, jsonlite, tibble, xts, xml2, utils, stats, methods, purrr, digest |
RoxygenNote: | 7.2.3 |
Suggests: | testthat (≥ 3.0.0), miniUI, shiny, dplyr, covr, withr |
Collate: | 'rbcb-package.R' 'rbcb_get.R' 'sgs.R' 'datasets.R' 'addins.R' 'rbcb_get_series.R' 'currency_helpers.R' 'utils.R' 'rbcb_get_currencies.R' 'odata-expectativas.R' 'odata_ptax.R' |
Config/testthat/edition: | 3 |
NeedsCompilation: | no |
Packaged: | 2024-01-25 21:19:47 UTC; wilso |
Repository: | CRAN |
Date/Publication: | 2024-01-25 21:30:02 UTC |
rbcb: R Interface to Brazilian Central Bank Web Services
Description
The Brazilian Central Bank API delivers many datasets which regard economic activity, regional economy, international economy, public finances, credit indicators and many more. For more information please see http://dadosabertos.bcb.gov.br/. These datasets can be accessed through 'rbcb' functions and can be obtained in different data structures common to R ('tibble', 'data.frame', 'xts', ...).
The Brazilian Central Bank API delivers many datasets which regard economic
activity, regional economy, international economy, public finances, credit
indicators and many more.
These datasets can be accessed through rbcb
functions and can be obtained in
different data structures common to R (tibble, data.frame, xts, ...).
See Also
Useful links:
Report bugs at https://github.com/wilsonfreitas/rbcb/issues
All currency values
Description
Gets all currency values
Usage
get_all_currencies(date)
Arguments
date |
reference date |
Value
A data.frame
with all currency values from the given date.
The currency rates come quoted in BRL.
Examples
## Not run:
get_all_currencies("2017-03-10")
## End(Not run)
Get annual market expectations of economic indicators
Description
Statistics for the annual expectations of economic indicators. All statistics are computed based on annual expectations provided by many financial institutions in Brazil: banks, funds, risk managers, so on and so forth. These expections and its statistics are used to build the FOCUS Report weekly released by the Brazilian Central Bank.
Usage
get_annual_market_expectations(
indic = NULL,
start_date = NULL,
end_date = NULL,
...
)
Arguments
indic |
a character vector with economic indicators names. They are case sensitive and don't forget the accents. |
start_date |
series initial date. Accepts ISO character formated date and |
end_date |
series final date. Accepts ISO character formated date and |
... |
additional parameters to be passed to the API
The |
Details
There are annual expectations available for the following indicators:
Balança Comercial
Câmbio
Conta corrente
Dívida bruta do governo geral
Dívida líquida do setor público
IGP-DI
IGP-M
INPC
Investimento direto no país
IPA-DI
IPA-M
IPCA
IPCA Administrados
IPCA Alimentação no domicílio
IPCA Bens industrializados
IPCA Livres
IPCA Serviços
IPCA-15
IPC-FIPE
PIB Agropecuária
PIB Despesa de consumo da administração pública
PIB despesa de consumo das famílias
PIB Exportação de bens e serviços
PIB Formação Bruta de Capital Fixo
PIB Importação de bens e serviços
PIB Indústria
PIB Serviços
PIB Total
Produção industrial
Resultado nominal
Resultado primário
Selic
Taxa de desocupação
Check <https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/documentacao#ExpectativasMercadoAnuais> for more details
Value
A data.frame
with the requested data.
Examples
## Not run:
indic <- c("PIB Total", "Fiscal")
end_date <- "2018-01-31"
x <- get_annual_market_expectations(indic, end_date = end_date, `$top` = 10)
# return all indicators for the specified date range
start_date <- "2021-01-01"
x <- get_annual_market_expectations(start_date = start_date, `$top` = 20)
## End(Not run)
Get currency values for a given period
Description
Given a currency symbol and a time interval (in dates) this function returns the bid and ask time series of currency rates.
Usage
get_currency(
symbol,
start_date,
end_date,
as = c("tibble", "xts", "data.frame", "text")
)
Arguments
symbol |
currency symbol |
start_date |
time interval initial date |
end_date |
time interval last date |
as |
the object's returning type The The time series date range is defined by |
Value
The time series with the bid and ask currency rates regarding the given symbol quoted in BRL.
The default returning is a tibble
-fashioned data.frame
with
the three columns: date
, ask
and bid
.
The as
argument also accepts data.frame
to return old fashioned data frames,
xts
to return a xts object with two variables (bid and ask) and text
which returns
the text content download from BCB site.
Examples
## Not run:
get_currency("USD", "2017-03-01", "2017-03-10")
## End(Not run)
Get currency matrix from BCB
Description
The currency matrix has the currency cross rates for all currencies present in the BCB system.
Usage
get_currency_cross_rates(date, ref = c("ask", "bid"))
Arguments
date |
reference date |
ref |
reffers to
|
Value
A square matrix
with colnames
and rownames
filled with currency symbols
The cells must be read as ROW
in COL
, for example, BRL (row) in USD (column) means Brazilian Reals in American Dollars.
Examples
## Not run:
x <- get_currency_cross_rates("2017-03-10")
currencies <- c("USD", "BRL", "AUD", "EUR", "CAD")
x[currencies, currencies]
## End(Not run)
Get market expectations
Description
General function to get statistics of market expectations. The API provides requests for annual, monthly, and quarterly expectations. Is is also proveided expectations for 12 months ahead, specific requests for the top 5 indicators for annual and monthly expectations and data provided by financial institutions.
Usage
get_market_expectations(
type = c("annual", "quarterly", "monthly", "inflation-12-months", "top5s-monthly",
"top5s-annual", "selic", "top5s-selic"),
indic = NULL,
start_date = NULL,
end_date = NULL,
keep_names = TRUE,
...
)
Arguments
type |
a character with one of the following: |
indic |
a character vector with economic indicators names. They are case sensitive and don't forget the accents. |
start_date |
series initial date.
Accepts ISO character formated date and |
end_date |
series final date.
Accepts ISO character formated date and |
keep_names |
if |
... |
additional parameters to be passed to the API
The |
Details
All statistics are computed based on expectations provided by many financial institutions in Brazil: banks, funds, risk managers, so on and so forth. These expections and its statistics are used to build the FOCUS Report weekly released by the Brazilian Central Bank.
There are market expectations available for the following indicators:
Balança Comercial
Câmbio
Conta corrente
Dívida bruta do governo geral
Dívida líquida do setor público
IGP-DI
IGP-M
INPC
Investimento direto no país
IPA-DI
IPA-M
IPCA
IPCA Administrados
IPCA Alimentação no domicílio
IPCA Bens industrializados
IPCA Livres
IPCA Serviços
IPCA-15
IPC-FIPE
PIB Agropecuária
PIB Despesa de consumo da administração pública
PIB despesa de consumo das famílias
PIB Exportação de bens e serviços
PIB Formação Bruta de Capital Fixo
PIB Importação de bens e serviços
PIB Indústria
PIB Serviços
PIB Total
Produção industrial
Resultado nominal
Resultado primário
Selic
Taxa de desocupação
Check <https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/documentacao> for more details
Value
A data.frame
with the requested data.
Examples
## Not run:
indic <- c("IPCA", "Câmbio")
x <- get_market_expectations("annual", indic, `$top` = 10)
x <- get_market_expectations("monthly", "Selic", `$top` = 20)
# get monthly expectations for top 5 indicators since 2021
x <- get_market_expectations("top5s-monthly", start_date = "2021-01-01")
# get annual expectations for top 5 indicators since 2021
x <- get_market_expectations("top5s-annual", `$top` = 20)
# get all inflation expectations for 12 months ahead starting on 2021-01
x <- get_market_expectations("inflation-12-months", start_date = "2021-01-01")
# get all SELIC expectations informed by financial institutions since 2022
x <- get_market_expectations("selic", start_date = "2022-01-01")
# get TOP5 SELIC expectations starting on 2022
x <- get_market_expectations("top5s-selic", start_date = "2022-01-01")
## End(Not run)
Get monthly market expectations of economic indicators
Description
Statistics for the monthly expectations of economic indicators. All statistics are computed based on monthly expectations provided by many financial institutions in Brazil: banks, funds, risk managers, so on and so forth. These expections and its statistics are used to build the FOCUS Report weekly released by the Brazilian Central Bank.
Usage
get_monthly_market_expectations(
indic = NULL,
start_date = NULL,
end_date = NULL,
...
)
Arguments
indic |
a character vector with economic indicators names. They are case sensitive and don't forget the accents. |
start_date |
series initial date. Accepts ISO character formated date and |
end_date |
series final date. Accepts ISO character formated date and |
... |
additional parameters to be passed to the API
The |
Details
There are monthly expectations available for the following indicators:
Câmbio
IGP-DI
IGP-M
INPC
IPA-DI
IPA-M
IPCA
IPCA Administrados
IPCA Alimentação no domicílio
IPCA Bens industrializados
IPCA Livres
IPCA Serviços
IPCA-15
IPC-Fipe
Produção industrial
Selic
Taxa de desocupação
Check <https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/documentacao#ExpectativaMercadoMensais> for more details
Value
A data.frame
with the requested data.
Examples
## Not run:
indic <- c("IPCA", "IPC-Fipe")
end_date <- "2018-01-31"
x <- get_monthly_market_expectations(indic, end_date = end_date, `$top` = 10)
# return all indicators for the specified date range
start_date <- "2021-01-01"
x <- get_monthly_market_expectations(start_date = start_date, `$top` = 20)
## End(Not run)
Get quarterly market expectations of economic indicators
Description
Statistics for the quarterly expectations of economic indicators. All statistics are computed based on quarterly expectations provided by many financial institutions in Brazil: banks, funds, risk managers, so on and so forth. These expections and its statistics are used to build the FOCUS Report weekly released by the Brazilian Central Bank.
Usage
get_quarterly_market_expectations(
indic = NULL,
start_date = NULL,
end_date = NULL,
...
)
Arguments
indic |
a character vector with economic indicators names. They are case sensitive and don't forget the accents. |
start_date |
series initial date. Accepts ISO character formated date and |
end_date |
series final date. Accepts ISO character formated date and |
... |
additional parameters to be passed to the API
The |
Details
There are quarterly expectations available for the following indicators:
Câmbio
IPCA
IPCA Administrados
IPCA Alimentação no domicílio
IPCA Bens industrializados
IPCA Livres
IPCA Serviços
PIB Agropecuária
PIB Indústria
PIB Serviços
PIB Total
Taxa de desocupação
Check <https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/documentacao#ExpectativasMercadoTrimestrais> for more details
Value
A data.frame
with the requested data.
Examples
## Not run:
indic <- c("PIB Industrial", "PIB Total")
end_date <- "2018-01-31"
x <- get_quarterly_market_expectations(indic, end_date = end_date, `$top` = 10)
# return all indicators for the specified date range
start_date <- "2021-01-01"
x <- get_quarterly_market_expectations(start_date = start_date, `$top` = 20)
## End(Not run)
Get Selic market expectations
Description
Statistics of Selic market expectations. All statistics are computed based on expectations provided by many financial institutions in Brazil: banks, funds, risk managers, so on and so forth. These expections and its statistics are used to build the FOCUS Report weekly released by the Brazilian Central Bank.
Usage
get_selic_market_expectations(start_date = NULL, end_date = NULL, ...)
Arguments
start_date |
series initial date.
Accepts ISO character formated date and |
end_date |
series final date.
Accepts ISO character formated date and |
... |
additional parameters to be passed to the API The |
Details
Check <https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/documentacao#ExpectativasMercadoSelic> for more details
Value
A data.frame
with the requested data.
Examples
## Not run:
# return all indicators for the specified date range
start_date <- "2022-01-01"
x <- get_selic_market_expectations(start_date = start_date, `$top` = 20)
## End(Not run)
Get the series from BCB
Description
Get the series from BCB
Usage
get_series(
code,
start_date = NULL,
end_date = NULL,
last = 0,
as = c("tibble", "xts", "ts", "data.frame", "text")
)
Arguments
code |
series code |
start_date |
series initial date. Accepts ISO character formated date and |
end_date |
series final date. Accepts ISO character formated date and |
last |
last items of the series |
as |
the returning type: data objects (
The arguments |
Value
tibble
is the default returning class, but the argument as
can be set
to xts
, data.frame
, ts
, or text
to return these other types.
text
returns the JSON data provided by the remote API.
Examples
# download the entire series
## Not run:
get_series(1)
## End(Not run)
# download a period of dates
## Not run:
get_series(1, start_date = "2016-12-01")
## End(Not run)
## Not run:
x <- get_series(1, start_date = "2016-12-01", end_date = "2016-12-31")
## End(Not run)
# downlaod the last register
## Not run:
x <- get_series(1, last = 1)
## End(Not run)
Get annual market expectations from top 5 providers
Description
Statistics of annual expectations for top 5 indicators. All statistics are computed based on expectations provided by many financial institutions in Brazil: banks, funds, risk managers, so on and so forth. These expections and its statistics are used to build the FOCUS Report weekly released by the Brazilian Central Bank.
Usage
get_top5s_annual_market_expectations(
indic = NULL,
start_date = NULL,
end_date = NULL,
...
)
Arguments
indic |
a character vector with economic indicators names. They are case sensitive and don't forget the accents. |
start_date |
series initial date.
Accepts ISO character formated date and |
end_date |
series final date.
Accepts ISO character formated date and |
... |
additional parameters to be passed to the API
The |
Details
There are inflation's expectations available for the following indicators:
Câmbio
IGP-DI
IGP-M
IPCA
Selic
Check <https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/documentacao#ExpectativasMercadoTop5Anuais> for more details
Value
A data.frame
with the requested data.
Examples
## Not run:
indic <- "IPCA"
end_date <- "2018-06-22"
x <- get_top5s_annual_market_expectations(indic, end_date = end_date, `$top` = 10)
# return all indicators for the specified date range
start_date <- "2021-01-01"
x <- get_top5s_annual_market_expectations(start_date = start_date, `$top` = 20)
## End(Not run)
Get monthly market expectations from top 5 providers
Description
Statistics of monthly expectations for top 5 indicators. All statistics are computed based on expectations provided by many financial institutions in Brazil: banks, funds, risk managers, so on and so forth. These expections and its statistics are used to build the FOCUS Report weekly released by the Brazilian Central Bank.
Usage
get_top5s_monthly_market_expectations(
indic = NULL,
start_date = NULL,
end_date = NULL,
...
)
Arguments
indic |
a character vector with economic indicators names. They are case sensitive and don't forget the accents. |
start_date |
series initial date.
Accepts ISO character formated date and |
end_date |
series final date.
Accepts ISO character formated date and |
... |
additional parameters to be passed to the API
The |
Details
There are inflation's expectations available for the following indicators:
Câmbio
IGP-DI
IGP-M
IPCA
Selic
Check <https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/documentacao#ExpectativasMercadoTop5Mensais> for more details
Value
A data.frame
with the requested data.
Examples
## Not run:
indic <- "IPCA"
end_date <- "2018-06-22"
x <- get_top5s_monthly_market_expectations(indic, end_date = end_date, `$top` = 10)
# return all indicators for the specified date range
start_date <- "2021-01-01"
x <- get_top5s_monthly_market_expectations(start_date = start_date, `$top` = 20)
## End(Not run)
Get Selic market expectations from top 5 providers
Description
Statistics of Selic expectations for top 5 indicators. All statistics are computed based on expectations provided by many financial institutions in Brazil: banks, funds, risk managers, so on and so forth. These expections and its statistics are used to build the FOCUS Report weekly released by the Brazilian Central Bank.
Usage
get_top5s_selic_market_expectations(start_date = NULL, end_date = NULL, ...)
Arguments
start_date |
series initial date.
Accepts ISO character formated date and |
end_date |
series final date.
Accepts ISO character formated date and |
... |
additional parameters to be passed to the API The |
Details
Check <https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/documentacao#ExpectativasMercadoTop5Selic> for more details
Value
A data.frame
with the requested data.
Examples
## Not run:
# return all indicators for the specified date range
start_date <- "2022-01-01"
x <- get_top5s_selic_market_expectations(start_date = start_date, `$top` = 20)
## End(Not run)
Get inflation's market expectations for the next 12 months
Description
Statistics of inflation's market expectations for the next 12 months. All statistics are computed based on expectations provided by many financial institutions in Brazil: banks, funds, risk managers, so on and so forth. These expections and its statistics are used to build the FOCUS Report weekly released by the Brazilian Central Bank.
Usage
get_twelve_months_inflation_expectations(
indic = NULL,
start_date = NULL,
end_date = NULL,
...
)
Arguments
indic |
a character vector with economic indicators names. They are case sensitive and don't forget the accents. |
start_date |
series initial date.
Accepts ISO character formated date and |
end_date |
series final date.
Accepts ISO character formated date and |
... |
additional parameters to be passed to the API
The |
Details
There are inflation's expectations available for the following indicators:
IGP-DI
IGP-M
INPC
IPA-DI
IPA-M
IPCA
IPCA Administrados
IPCA Alimentação no domicílio
IPCA Bens industrializados
IPCA Livres
IPCA Serviços
IPCA-15
IPC-FIPE
Check <https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/documentacao#ExpectativasMercadoInflacao12Meses> for more details
Value
A data.frame
with the requested data.
Examples
## Not run:
indic <- c("IPCA", "IGP-M")
end_date <- "2018-06-22"
x <- get_twelve_months_inflation_expectations(indic, end_date = end_date, `$top` = 10)
# return all indicators for the specified date range
start_date <- "2021-01-01"
x <- get_twelve_months_inflation_expectations(start_date = start_date, `$top` = 20)
## End(Not run)
Helpers to access time series columns
Description
Extraxt bid and ask data from time series objects.
Usage
Bid(x, ...)
## S3 method for class 'data.frame'
Bid(x, ...)
## S3 method for class 'xts'
Bid(x, ...)
## S3 method for class 'olinda_df'
Bid(x, ...)
Ask(x, ...)
## S3 method for class 'data.frame'
Ask(x, ...)
## S3 method for class 'xts'
Ask(x, ...)
## S3 method for class 'olinda_df'
Ask(x, ...)
Arguments
x |
time series objects containing data to be extracted |
... |
additional arguments |
Value
tibble with time series
Examples
## Not run:
x <- get_currency("EUR", "2018-06-22", "2018-06-28")
Bid(x)
Ask(x)
## End(Not run)
List all currencies
Description
Lists all currencies and presents their name, symbol, numeric code, country name and county numeric code
Usage
list_currencies()
Value
A data.frame
with information of all currencies
Examples
## Not run:
list_currencies()
## End(Not run)
Get currency values for a given period
Description
Given a currency symbol and a time interval (in dates) this function returns the bid and ask time series of currency rates.
Usage
olinda_get_currency(
symbol,
start_date,
end_date = NULL,
as = c("tibble", "xts", "data.frame", "text"),
parity = FALSE
)
Arguments
symbol |
currency symbol |
start_date |
time interval initial date |
end_date |
time interval last date |
as |
the object's returning type |
parity |
The The time series date range is defined by The |
Value
The time series with the bid and ask currency rates regarding the given symbol quoted in BRL.
The default returning is a tibble
-fashioned data.frame
with
the three columns: date
, ask
and bid
.
The as
argument also accepts data.frame
to return old fashioned data frames,
xts
to return a xts object with two variables (bid and ask) and text
which returns
the text content download from BCB site.
Examples
## Not run:
olinda_get_currency("USD", "2017-03-01", "2017-03-10")
## End(Not run)
List all currencies
Description
Lists all currencies and presents their name, symbol, numeric code, country name and county numeric code
Usage
olinda_list_currencies()
Value
A data.frame
with information of all currencies.
The currency_type
refers to the currency's parity quotation.
Parity quotations relates currency values with USD.
Examples
## Not run:
list_currencies()
## End(Not run)
rbcb options
Description
Options used in rbcb inside some of its functions.
Details
* 'rbcb_cache': all downloaded data is stored in temporary directories, if 'rbcb_cache' is FALSE downloaded data overwrites files if it already exists. Otherwise, download is not executed and the existing file is returned. Defaults to TRUE. * 'rbcb_verbose': if TRUE verbose messages are displayed when http requests are executed with httr. Defaults to FALSE.
Examples
## Not run:
options(rbcb_cache = FALSE)
options(rbcb_verbose = TRUE)
## End(Not run)
rbcb dataset
Description
'rbcb_dataset(name)' opens an [RStudio gadget](https://shiny.rstudio.com/articles/gadgets.html) and [addin](http://rstudio.github.io/rstudioaddins/) that allows you to view a few attributes that help to explain the desired data.
Usage
rbcb_dataset(name)
Arguments
name |
dataset name |
Value
Addin has no return
Gets data from BCB open data services
Description
Gets SGS, currency, market expectations and many other datasets from the Brazilian Central Bank open data services.
Usage
rbcb_get(x, ...)
## S3 method for class 'sgs'
rbcb_get(x, from = NULL, to = NULL, last = 0, ...)
Arguments
x |
an object that represents the kind of data to be downloaded |
... |
others arguments |
from |
series initial date. Accepts ISO character formated date and
|
to |
series final date. Accepts ISO character formated date and
|
last |
last items of the series To use the SGS API a 'sgs' object should be passed. |
Value
a dataset with the corresponding data (usually a 'tibble')
Examples
## Not run:
x <- sgs(USD = 1, SELIC = 1178)
rbcb_get(x, from = Sys.Date() - 10)
## End(Not run)
rbcb Search
Description
'rbcb_search(text)' opens an [RStudio gadget](https://shiny.rstudio.com/articles/gadgets.html) and [addin](http://rstudio.github.io/rstudioaddins/) that allows you to query for specific terms and see a suitable rbcb command to fetch the desired data.
Usage
rbcb_search(text = "")
Arguments
text |
text to search |
Value
Addin has no return
Create SGS code
Description
SGS code is an objects that represents the SGS code used to download datasets from the SGS API.
Usage
sgs(..., load_info = TRUE)
Arguments
... |
numeric codes (preferably named) |
load_info |
'logical' indicating with the dataset info shoud be loaded (default TRUE) |
Value
an SGS object representing SGS codes
Examples
## Not run:
sgs(USD = 1, IPCA = 433)
## End(Not run)
Convert tidy dataframe into a list
Description
Convert a tidy dataframe into a list of separate time series objects like 'xts' and 'ts' or even a 'tibble' with a time series representation ( two columns with dates and values).
Usage
sgs_untidy(x, tidydf, as = c("tibble", "xts", "ts"))
Arguments
x |
sgs object with the corresponding codes |
tidydf |
tidy dataframe returned by 'rbcb_get' |
as |
the returning type ('tibble', 'xts', 'ts') |
Value
a list with time series objects
Examples
## Not run:
x <- sgs(USD = 1, SELIC = 1178)
df <- rbcb_get(x, from = Sys.Date() - 10)
sgs_untidy(x, df, as = "xts")
## End(Not run)