Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: brfinance
Title: Simplified Access to Brazilian Financial and Macroeconomic Data
Version: 0.7.1.900
Version: 0.7.2.900
Authors@R:
person(given = "João Paulo", family = "dos Santos Pereira Barbosa", email = "joao.31582129@gmail.com",role = c("aut", "cre"))
Description: It offers simplified access to Brazilian macroeconomic and financial indicators selected from official sources, such as the 'IBGE' (Brazilian Institute of Geography and Statistics) via the 'SIDRA' API and the 'Central Bank of Brazil' via the 'SGS' API. It allows users to quickly retrieve and visualize data series such as the unemployment rate and the Selic interest rate. This package was developed for data access and visualization purposes, without generating forecasts or statistical results. For more information, see the official APIs: <https://sidra.ibge.gov.br/> and <https://dadosabertos.bcb.gov.br/dataset/>.
Expand All @@ -10,7 +10,7 @@ BugReports: https://github.com/efram2/brfinance/issues
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
Depends:
R (>= 4.1.0)
Imports:
Expand Down
10 changes: 7 additions & 3 deletions R/plot_series_comparison.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
#' @param y_vars Vector of column names containing the values to plot from each data frame
#' @param date_vars Vector of column names containing dates from each data frame
#' @param language Language for labels: "pt" (Portuguese) or "eng" (English)
#' @param scale_type Type of scaling: "none" (raw values), "index" (index to 100),
#' "percent_change" (percentage change from first observation)
#' @param scale_type Scaling applied to the series:
#' \describe{
#' \item{"none"}{Plots raw values as provided}
#' \item{"index"}{Indexes all series to 100 at the first observation}
#' \item{"percent_change"}{Plots percentage change relative to the first observation}
#' }
#' @param title Plot title
#' @param subtitle Plot subtitle
#' @param y_label Y-axis label
Expand All @@ -29,7 +33,7 @@
#'
#' comparison_plot <- plot_series_comparison(
#' data_list = list(SELIC = selic, IPCA = ipca, IGP-M = igpm),
#' y_vars = c("rate", "value", "value"),
#' y_vars = c("value", "value", "value"),
#' date_vars = c("date", "date", "date"),
#' scale_type = "index",
#' title = "Comparison of Brazilian Economic Indicators",
Expand Down
45 changes: 22 additions & 23 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
.onAttach <- function(libname, pkgname) {
packageStartupMessage(
"====================================================\n",
"brfinance - Democratizing access to Brazilian economic data\n",
"====================================================\n\n",
"brfinance: Brazilian macroeconomic data and financial tools\n",
"------------------------------------------------------------\n\n",

"DOWNLOAD ECONOMIC DATA:\n",
" * get_selic_rate() - SELIC interest rate (annual)\n",
" * get_inflation_rate() - IPCA inflation with YTD & 12-month rates\n",
" * get_unemployment() - Quarterly unemployment rate (IBGE PNAD)\n",
" * get_exchange_rate() - US Dollar exchange rate (commercial)\n",
" * get_cdi_rate() - CDI interbank rate\n",
" * get_gdp_growth() - Quarterly GDP growth rate\n\n",
"Data access functions (examples):\n",
" get_selic_rate() SELIC interest rate\n",
" get_inflation_rate() IPCA inflation indicators\n",
" get_unemployment() Unemployment rate (PNAD Continua)\n",
" get_exchange_rate() Exchange rates\n",
" get_cdi_rate() CDI interbank rate\n",
" get_gdp_growth() GDP growth rates\n\n",

"VISUALIZE DATA:\n",
" * plot_selic_rate() - Plot SELIC evolution\n",
" * plot_unemployment() - Plot unemployment trends\n",
" * More plots coming soon!\n\n",
"Visualization helpers:\n",
" plot_selic_rate()\n",
" plot_unemployment()\n",
" plot_series_comparison()\n\n",

"KEY FEATURES:\n",
" * Set language = 'pt' for Portuguese column names\n",
" * Flexible date formats: YYYY, YYYY-MM, or YYYY-MM-DD\n",
" * Automatic variable labels with labelled package\n",
" * Built-in data validation and error handling\n\n",
"General features:\n",
" Flexible date inputs: YYYY, YYYY-MM, YYYY-MM-DD\n",
" Language support: English (default) or Portuguese\n",
" Consistent outputs across data sources\n\n",

"Learn more: browseVignettes('brfinance')\n",
"Report issues: https://github.com/efram2/brfinance/issues\n\n",
"See documentation:\n",
" ?brfinance\n",
" browseVignettes('brfinance')\n\n",

"Developed by Joao Paulo dos Santos P. Barbosa (efram2)\n",
"Contribute: https://github.com/efram2/brfinance"
"Issues & contributions:\n",
" https://github.com/efram2/brfinance"
)
}
179 changes: 179 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
---
title: "README"
output: github_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
message = FALSE,
warning = FALSE,
fig.align = "center"
)
library(brfinance)
```

# brfinance 📊🇧🇷

[![CRAN Status](https://www.r-pkg.org/badges/version/brfinance)](https://cran.r-project.org/package=brfinance)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![R-CMD-check](https://github.com/efram2/brfinance/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/efram2/brfinance/actions/workflows/R-CMD-check.yaml)
[![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/brfinance)](https://cran.r-project.org/package=brfinance)
[![Downloads](https://cranlogs.r-pkg.org/badges/brfinance)](https://cran.r-project.org/package=brfinance)
[![GitHub stars](https://img.shields.io/github/stars/efram2/brfinance.svg)](https://github.com/efram2/brfinance/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/efram2/brfinance.svg)](https://github.com/efram2/brfinance/network)

**brfinance** is an R package that brings together **official Brazilian macroeconomic data** and **practical financial calculators** in a simple, ready-to-use interface.

If you work with **Brazilian data**, **interest rates**, **inflation**, or **financial math**, this package is for you.

---

## Why brfinance?

With **brfinance**, you can:

- Access **official Brazilian macroeconomic indicators** (BCB & IBGE)
- Run **financial calculations** (NPV, IRR, PV, FV, PMT, rates)
- Plot key indicators with **one line of code**
- Use **Portuguese or English** outputs seamlessly

No APIs. No scraping. No manual cleaning.

---

# Installation

```r
install.packages("brfinance")

# Or development version from GitHub
install.packages("devtools")
devtools::install_github("efram2/brfinance")

library(brfinance)

```
# 🚀 Quick Start

**Inflation (IPCA)**

```{r fig.ipca, fig.width=7, fig.height=4}
plot_inflation_rate(
get_inflation_rate("2020", "2024")
)
```

**SELIC interest rate**

```{r fig.selic, fig.width=7, fig.height=4}
plot_selic_rate(
get_selic_rate(2020, 2024)
)
```

**Unemployment rate**

```{r fig.unemp, fig.width=7, fig.height=4}
plot_unemployment(
get_unemployment("2019", "2024")
)
```

**Compare multiple indicators in one chart**

You can compare different economic indicators using:
1. raw values
2. indexed series (base = first observation)
3. percentage change from the first observation

* Want to analyze how different economic indicators evolve together?
* Use *plot_series_comparison()* to compare multiple time series in a single, clean visualization.

```{r fig.compare, fig.width=8, fig.height=5}
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)"
)
```

**Financial Calculators (minimalista)**

```r
# Net Present Value
calc_npv(0.1, c(-1000, 300, 400, 500))

# Internal Rate of Return
calc_irr(c(-1000, 300, 400, 500))

# Loan payment
calc_pmt(rate = 0.02, n = 24, pv = 10000)
```
# Function Reference

## Data retrieval functions (`get_*`)

* `get_inflation_rate()` → Retrieves Brazil’s official inflation rate (IPCA)
* `get_selic_rate()` → Retrieves the SELIC interest rate
* `get_cdi_rate()` → Retrieves the CDI interest rate
* `get_exchange_rate()` → Retrieves official exchange rates
* `get_gdp_growth()` → Retrieves GDP growth rates
* `get_unemployment()` → Retrieves unemployment rate from PNAD Contínua
* `get_sgs_series()` → Retrieves any Central Bank (SGS) time series by code

All `get_*` functions support flexible date inputs:
`"YYYY"`, `"YYYY-MM"`, or `"YYYY-MM-DD"`.

---

## Plotting functions (`plot_*`)

* `plot_inflation_rate()` → Plots IPCA inflation over time
* `plot_selic_rate()` → Plots the SELIC interest rate
* `plot_cdi_rate()` → Plots the CDI interest rate
* `plot_exchange_rate()` → Plots exchange rate time series
* `plot_gdp_growth()` → Plots GDP growth over time
* `plot_unemployment()` → Plots unemployment rate time series
* `plot_series_comparison()` → Compares multiple economic indicators in one chart

---

## Financial calculators (`calc_*`)

* `calc_pv()` → Present Value
* `calc_fv()` → Future Value
* `calc_npv()` → Net Present Value
* `calc_irr()` → Internal Rate of Return
* `calc_pmt()` → Loan payment calculation
* `calc_rate()` → Interest rate calculation
* `calc_nper()` → Number of periods
* `calc_compound_interest()` → Compound interest calculation
* `calc_continuous_interest()` → Continuous compounding
* `calc_rule72()` → Rule of 72 approximation
* `calc_rule114()` → Rule of 114 approximation

# Language Support

All main functions support bilingual output:

* language = "eng" (default): Returns English column names and labels
* language = "pt": Returns Portuguese column names and labels

# Data sources

All data come from *official Brazilian institutions:*

* Central Bank of Brazil (BCB / SGS)
* IBGE (SIDRA / PNAD Contínua)

# Contribution

Suggestions, feature requests, and pull requests are welcome!
Loading