The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
brfinance provides a unified, consistent R interface for accessing Brazilian macroeconomic data and performing core financial math calculations.
Instead of writing custom API wrappers, parsing raw JSON responses,
or dealing with inconsistent date formats, brfinance
standardizes macroeconomic series into clean data.frame
outputs with consistent date and value
structure. It also includes built-in ggplot2 visualization
functions and essential corporate finance routines.
PMT),
amortization schedules, interest rate conversions, and rule
estimates.ggplot2 charts with unified color
palettes and customizable scaling (raw, indexed, percentage change, or
dual-axis).YYYY, YYYY-MM, YYYY-MM-DD), and
bilingual metadata support (English and
Portuguese).Looking for individual stock analysis?
brfinancefocuses on macroeconomic indicators and market benchmarks. For individual B3 equity data, portfolio optimization, and Markowitz analysis, see the companion package {brstocks}.
Install the stable version from CRAN:
install.packages("brfinance")Or install the development version from GitHub:
# install.packages("devtools")
devtools::install_github("efram2/brfinance")Load the package:
library(brfinance)Every data retrieval function (get_*) returns a
standardized data.frame with date and
value columns (plus specialized columns where
appropriate).
Inflation Rate (IPCA)
plot_inflation_rate(
get_inflation_rate("2020", "2024")
)
SELIC Interest Rate
plot_selic_rate(
get_selic_rate("2020", "2024")
)
Unemployment Rate (PNAD ContÃnua)
plot_unemployment(
get_unemployment("2019", "2024")
)
Ibovespa Index Benchmark
plot_ibovespa(
get_ibovespa("2020-01-01", "2024-12-31")
)
IPCA vs. Inflation Target Gap
Evaluate whether inflation is operating within the National Monetary Council (CMN) target parameters:
ipca_gap <- get_ipca_from_target("2015", "2024")
head(ipca_gap) date ipca_12m target gap
1 2015-01-01 7.14 4.5 2.64
2 2015-02-01 7.70 4.5 3.20
3 2015-03-01 8.13 4.5 3.63
4 2015-04-01 8.17 4.5 3.67
5 2015-05-01 8.47 4.5 3.97
6 2015-06-01 8.89 4.5 4.39
Multi-Series Comparison (Indexed)
Compare indicators across different scales by indexing from the first observation (Base = 100):
plot_series_comparison(
data_list = list(
"SELIC" = get_selic_rate("2020", "2024"),
"IPCA" = get_inflation_rate("2020", "2024"),
"Unemployment" = get_unemployment("2020", "2024")
),
y_vars = rep("value", 3),
date_vars = rep("date", 3),
scale_type = "index",
title = "Brazilian Economic Indicators",
subtitle = "Indexed comparison (base = first observation)"
)
Dual-Axis Comparison
Compare two indicators with different original units (e.g., % rate vs. currency rate) without loss of scale resolution:
plot_series_comparison(
data_list = list(
"SELIC" = get_selic_rate("2020", "2024"),
"Exchange Rate" = get_exchange_rate("2020-01-01", "2024-12-31")
),
y_vars = c("value", "value"),
date_vars = c("date", "date"),
dual_axis = TRUE,
title = "SELIC vs. USD/BRL Exchange Rate"
)
# Net Present Value (NPV)
calc_npv(rate = 0.1, cashflows = c(-1000, 300, 400, 500))
#> [1] -21.03681
# Internal Rate of Return (IRR)
calc_irr(cashflows = c(-1000, 300, 400, 500))
#> [1] 0.08896339
# Periodic Loan Payment (PMT)
calc_pmt(pv = 10000, rate = 0.02, n = 24)
#> [1] 528.711
# Amortization Schedule (First 3 periods)
head(calc_amortization_schedule(pv = 10000, rate = 0.01, n = 12), 3)
#> Period Beginning_Balance Payment Interest Principal Ending_Balance
#> 1 1 10000.00 888.4879 100.0000 788.4879 9211.512
#> 2 2 9211.51 888.4879 92.1151 796.3728 8415.139
#> 3 3 8415.14 888.4879 84.1514 804.3365 7610.803get_*)| Function | Description | Source |
|---|---|---|
get_inflation_rate() |
Brazil’s official monthly inflation rate (IPCA) | BCB / SGS |
get_ipca_from_target() |
12-month accumulated IPCA vs. official CMN target and gap | BCB / SGS |
get_selic_rate() |
Daily SELIC interest rate, annualized (base 252) | BCB / SGS |
get_cdi_rate() |
Daily CDI interbank rate, annualized | BCB / SGS |
get_exchange_rate() |
Daily USD/BRL exchange rate | BCB / SGS |
get_gdp_growth() |
Quarterly and annual GDP growth rates | BCB / SGS |
get_unemployment() |
Unemployment rate (PNAD ContÃnua) | IBGE via BCB SGS |
get_ibovespa() |
Ibovespa market index closing levels | Yahoo Finance |
browse_series() /
get_series_info() |
Catalog exploration tools for additional Central Bank series | BCB / SGS |
Query Handling & Features: - Date
Flexibility: Accepts "YYYY",
"YYYY-MM", or "YYYY-MM-DD". -
Automatic Chunking: Queries spanning more than 10 years
are automatically partitioned into sub-requests to respect Central Bank
API limitations and joined seamlessly.
plot_*)| Function | Description | Visual Palette |
|---|---|---|
plot_inflation_rate() |
Time series plot of IPCA inflation | Market Red (Cost/Risk) |
plot_selic_rate() |
Time series plot of SELIC interest rate | Market Blue (Benchmark) |
plot_cdi_rate() |
Time series plot of CDI interest rate | Market Blue (Benchmark) |
plot_exchange_rate() |
Time series plot of USD/BRL exchange rate | Market Blue (Benchmark) |
plot_unemployment() |
Time series plot of PNAD ContÃnua unemployment | Market Red (Cost/Risk) |
plot_ibovespa() |
Time series plot of Ibovespa index level | Market Blue (Benchmark) |
plot_series_comparison() |
Multi-indicator comparison chart (raw, indexed, % change, or dual-axis) | Multi-color palette |
calc_* & Rules)calc_present_value(), calc_future_value(),
calc_compound_interest(),
calc_future_value_ext()calc_pv_annuity(), calc_fv_annuity(),
calc_pmt()calc_rate(),
calc_nper(), calc_simple_interest(),
calc_effective_rate(),
calc_nominal_rate()calc_npv(),
calc_irr(), calc_amortization_schedule()calc_continuous_compounding(),
calc_pv_continuous()rule_of_72(),
rule_of_114()Data integrated into brfinance comes from the following
providers:
get_ibovespa()).All get_*() functions include a language
parameter:
language = "eng" (default): Returns English
variable labels.language = "pt": Returns Portuguese variable
labels.Pipeline Consistency: Core data frame column names (
date,value, etc.) remain identical regardless of language selection. Changinglanguagealters only the descriptive variable labels (accessible vialabelled::var_label()), ensuring existing data transformation pipelines do not break.
Contributions, issue reports, and feature requests are welcome! Feel free to open an issue or pull request on GitHub.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.