You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This simple library allows users to access Brazil Central Bank (BACEN) data by interacting with its API. The library consists of three main R scripts that work together:
Bacen_URL: Generates the URL where the data is available.
Bacen_API: Connects with the BACEN API, extracts the requested information, and converts it to a readable format.
Bacen_series: Retrieves data from multiple Central Bank series, given a vector of series IDs and corresponding names.
bacen_search: Searches for financial indicator series using keywords in Portuguese.
dataset: object is a preloaded data frame containing metadata about the financial indicator series available from the Central Bank of Brazil (BACEN).
This README provides a detailed guide on how to use each function.
Bacen_URL
Description
This function generates the URL for accessing BACEN data by specifying three arguments:
series: The series code.
star_date: The start date.
end_date: The end date.
Important Notes
Use the Brazilian date format:dd/mm/yyyy.
Ensure dates are provided as strings/characters.
Example
# Generate URL for IPCA series from 01/01/2003 to 31/12/2023ipca_br_url<- bacen_url(433,'01/01/2003','31/12/2023')# Outputprint(ipca_br_url)
This function connects to the BACEN API using either thehttr orhttr2 package. It internally verifies the HTTP status code (e.g.,200 for success,400/404 for failure) and retries up to three times if the initial connection fails.
Arguments
url: The URL generated using theBacen_URL function.
httr: A logical variable indicating whether to usehttr. Defaults toTRUE.
Example
# URL for IPCA seriesipca_br_url<- bacen_url(433,'01/01/2003','31/12/2023')# Access API datadata<- bacen_api(url=ipca_br_url,httr=TRUE)# Display resultsprint(head(data))
Thebacen_search() function allows users to search for financial indicator series based on keywords. It is useful when the exact series code is unknown, but a topic or name is available.
Arguments
keyword: A character string (in Portuguese) containing the search term. Example:"câmbio","juros","Bovespa","fortaleza".
Returns
Adata.frame with the following columns:
Code: The series number from BACEN.
Full_Name: The full name of the financial indicator (truncated to 50 characters for readability).
Unit: The unit of measurement of the indicator.
Periodicity: Frequency of the series (e.g., Monthly, Daily).
Start_Date: The initial date when the series began.
If no matches are found, an informative message will be printed and the function returnsNULL.
Example
# Search for financial indicators related to "fortaleza"bacen_search("fortaleza")
Sample Output:
Code Full_Name Unit Periodicity Start_Date1 1619 Índice de Preços ao Consumidor - Fortaleza % Monthly 01/01/19912 4414 Índice Nacional de Preços ao Consumidor - Fortaleza % Monthly 01/01/1991
dataset
Description
Thedataset object is a preloaded data frame containing metadata about the financial indicator series available from the Central Bank of Brazil (BACEN). It is used internally by thebacen_search() function and can also be accessed directly by users for custom searches and exploration.
Format
Adata.frame with multiple rows and the following 5 columns:
Code:(character) The unique identifier for each financial indicator series.
Full_Name:(character) The full name or description of the financial indicator.
Unit:(character) The unit of measurement used for the data (e.g., %, R$, index value).
Periodicity:(character) The frequency with which data is collected (e.g., Daily, Monthly, Annual).
Start_Date:(Date) The date on which the series began.
Source
Data collected and compiled from theCentral Bank of Brazil (BACEN).
Example
# Load the datasetdata("dataset")# Preview the first few rowshead(dataset)
Footnotes
Customize series codes and date ranges as per your needs.