View source: R/get_inflation_rate.R
| get_inflation_rate | R Documentation |
Downloads monthly IPCA (Broad National Consumer Price Index) inflation data from the Brazilian Central Bank's SGS API and calculates accumulated inflation rates. IPCA is Brazil's official inflation index, calculated monthly by IBGE.
get_inflation_rate(
start_date = "2012-01-01",
end_date = NULL,
language = "eng",
labels = TRUE
)
start_date |
Start date for the data period. Accepts multiple formats:
|
end_date |
End date for the data period. Accepts the same formats as
|
language |
Language for column names in the returned data.frame:
|
labels |
Logical indicating whether to add variable labels using the |
A data.frame with inflation metrics. Columns depend on the language parameter:
English (language = "eng"):
date (Date): Reference month
monthly_inflation (numeric): Monthly IPCA variation (%)
ytd_inflation (numeric): Year-to-date accumulated inflation (%)
twelve_month_inflation (numeric): 12-month accumulated inflation (%)
Portuguese (language = "pt"):
data_referencia (Date): Mes de referencia
inflacao_mensal (numeric): Variacao mensal do IPCA (%)
inflacao_acumulada_ano (numeric): Inflacao acumulada no ano (%)
inflacao_12_meses (numeric): Inflacao acumulada nos ultimos 12 meses (%)
Default Period: When start_date = NULL, defaults to "2020-01-01", providing
data from the start of 2020. This period covers significant economic events including
the COVID-19 pandemic and recent inflationary pressures in Brazil.
Data Processing: This function automatically downloads an extra 12 months of historical data to calculate 12-month accumulated inflation correctly. The final output is filtered to show only the requested period.
Calculation Details:
Year-to-date inflation: Cumulative product of monthly rates within each calendar year
12-month inflation: Rolling 12-month cumulative product of monthly rates
# Default: from 2020 to current date (aligned with SELIC function)
df <- get_inflation_rate()
# Specific period with year-only format
df2 <- get_inflation_rate("2021", "2023")
# Using year-month format for precise month selection
df3 <- get_inflation_rate("2022-03", "2023-06")
# Portuguese column names and labels
df4 <- get_inflation_rate(language = "pt")
# Without variable labels
df5 <- get_inflation_rate("2020-01-01", "2022-12-31", labels = FALSE)
# Current year analysis
current_year <- format(Sys.Date(), "%Y")
df6 <- get_inflation_rate(start_date = current_year)
# Compare with SELIC rate (same default period)
selic_data <- get_selic_rate() # Also starts at 2020-01-01
inflation_data <- get_inflation_rate() # Same start date
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.