Learn R Programming

brfinance (version 0.8.0)

get_inflation_rate: Get IPCA Inflation Data

Description

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.

Usage

get_inflation_rate(
  start_date = "2012-01-01",
  end_date = NULL,
  language = "eng",
  labels = TRUE
)

Value

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 (%)

Arguments

start_date

Start date for the data period. Accepts multiple formats:

  • "YYYY" for year only (e.g., "2020" becomes "2020-01-01")

  • "YYYY-MM" for year and month (e.g., "2020-06" becomes "2020-06-01")

  • "YYYY-MM-DD" for a specific date (e.g., "2020-06-15")

  • NULL defaults to "2020-01-01" (aligned with other functions in the package)

end_date

End date for the data period. Accepts the same formats as start_date:

  • "YYYY" (e.g., "2023" becomes "2023-12-31")

  • "YYYY-MM" (e.g., "2023-12" becomes the last day of December 2023)

  • "YYYY-MM-DD" for a specific date

  • NULL defaults to the current date (today)

language

Language for column names in the returned data.frame:

  • "eng" (default): Returns columns date, monthly_inflation, ytd_inflation, twelve_month_inflation

  • "pt": Returns columns data_referencia, inflacao_mensal, inflacao_acumulada_ano, inflacao_12_meses

labels

Logical indicating whether to add variable labels using the labelled package. Labels provide descriptive text for each column when available.

Examples

Run this code
if (FALSE) { # interactive()
  # 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
}

Run the code above in your browser using DataLab