{"id":13741268,"url":"https://github.com/ropensci/rb3","last_synced_at":"2026-02-21T17:36:17.673Z","repository":{"id":24624000,"uuid":"28033021","full_name":"ropensci/rb3","owner":"ropensci","description":"A bunch of downloaders and parsers for data delivered from B3","archived":false,"fork":false,"pushed_at":"2025-11-01T11:13:00.000Z","size":56910,"stargazers_count":86,"open_issues_count":24,"forks_count":35,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-11-01T13:06:36.523Z","etag":null,"topics":["brazil","exchange-data","finance","financial-data","financial-services","market-data","r"],"latest_commit_sha":null,"homepage":"https://docs.ropensci.org/rb3/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ropensci.png","metadata":{"files":{"readme":"README.R","changelog":"NEWS.md","contributing":"Contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2014-12-15T11:04:39.000Z","updated_at":"2025-11-01T11:06:34.000Z","dependencies_parsed_at":"2023-02-13T04:01:17.438Z","dependency_job_id":"f075cab3-b312-41cb-acbf-2d766e13f8ec","html_url":"https://github.com/ropensci/rb3","commit_stats":{"total_commits":400,"total_committers":4,"mean_commits":100.0,"dds":"0.19999999999999996","last_synced_commit":"f23e08bed98d0ab0be876187f3ee5ea2ebc61ce5"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/ropensci/rb3","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Frb3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Frb3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Frb3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Frb3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ropensci","download_url":"https://codeload.github.com/ropensci/rb3/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ropensci%2Frb3/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29688351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-21T15:51:39.154Z","status":"ssl_error","status_checked_at":"2026-02-21T15:49:03.425Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["brazil","exchange-data","finance","financial-data","financial-services","market-data","r"],"created_at":"2024-08-03T04:00:57.360Z","updated_at":"2026-02-21T17:36:17.629Z","avatar_url":"https://github.com/ropensci.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":["Data Sources"],"readme":"\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n# rb3 \u003cimg src=\"man/figures/logo.png\" align=\"right\" width=\"120\" alt=\"rb3\" /\u003e\n\n\u003c!-- badges: start --\u003e\n\n[![Project Status: Active – The project has reached a stable, usable\nstate and is being actively\ndeveloped.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)\n[![Codecov test\ncoverage](https://codecov.io/gh/wilsonfreitas/rb3/branch/main/graph/badge.svg)](https://app.codecov.io/gh/wilsonfreitas/rb3?branch=main)\n[![R build\n(rcmdcheck)](https://github.com/ropensci/rb3/workflows/R-CMD-check/badge.svg)](https://github.com/ropensci/rb3/actions)\n[![CRAN\nstatus](https://www.r-pkg.org/badges/version/rb3)](https://CRAN.R-project.org/package=rb3)\n[![rb3\ndownloads](https://cranlogs.r-pkg.org/badges/rb3)](https://cran.r-project.org/package=rb3)\n[![Status at rOpenSci Software Peer\nReview](https://badges.ropensci.org/534_status.svg)](https://github.com/ropensci/software-review/issues/534)\n\u003c!-- badges: end --\u003e\n\n## Overview\n\n[B3](https://www.b3.com.br) is the main financial exchange in Brazil,\noffering access to trading systems for stocks, futures, options, and\nother financial instruments. The `rb3` package provides tools for\ndownloading, processing, and analyzing market data from B3, including:\n\n- **Stocks \u0026 Equities**: Historical price data through COTAHIST files\n- **Futures Contracts**: Settlement prices for futures contracts\n- **Yield Curves**: Historical yield curves calculated from futures\n  contracts\n- **ETFs \u0026 BDRs**: Data for Exchange Traded Funds and Brazilian\n  Depositary Receipts\n- **REITs (FIIs)**: Data for Brazilian Real Estate Investment Trusts\n- **Options**: Equity and index options contracts\n- **Market Indices**: B3 indices composition and historical data\n\nThe package uses webscraping tools to obtain data directly from [B3’s\nwebsite](https://www.b3.com.br), making it accessible in R as structured\ndatasets. These datasets are valuable for financial analysis, academic\nresearch, and investment decision-making.\n\n## Installation\n\n``` r\n# From CRAN (stable version)\ninstall.packages(\"rb3\")\n\n# Development version from GitHub\nif (!require(devtools)) install.packages(\"devtools\")\ndevtools::install_github(\"ropensci/rb3\")\n```\n\n## Basic Usage\n\n### Downloading Data\n\nExecute the following code to download all data you need to start\nworking with `rb3`:\n\n``` r\n# Set the rb3.cachedir folder - it must be executed before loading rb3 package\noptions(rb3.cachedir = \"/path/to/your/custom/folder\")\n\nlibrary(rb3)\nlibrary(bizdays)\n\n# download COTAHIST data from 2000 to 2025\nfetch_marketdata(\"b3-cotahist-yearly\", year = 2000:2025)\n# download futures settlement prices from 2000 to 2025\nfetch_marketdata(\"b3-futures-settlement-prices\", refdate = bizseq(\"2000-01-01\", Sys.Date(), \"Brazil/B3\"))\n# download yield curves from 2018 to 2025\nfetch_marketdata(\"b3-reference-rates\",\n  refdate = bizseq(\"2018-01-01\", Sys.Date(), \"Brazil/B3\"),\n  curve_name = c(\"DIC\", \"DOC\", \"PRE\")\n)\n# download indexes composition data - it is necessary to execute `indexes_get()`\nfetch_marketdata(\"b3-indexes-composition\")\n# download current portfolio for all indexes\nfetch_marketdata(\"b3-indexes-current-portfolio\", index = indexes_get(), throttle = TRUE)\n# download theoretical portfolio for all indexes\nfetch_marketdata(\"b3-indexes-theoretical-portfolio\", index = indexes_get(), throttle = TRUE)\n# download historical data for all indexes\nfetch_marketdata(\"b3-indexes-historical-data\", index = indexes_get(), year = 2000:2025, throttle = TRUE)\n```\n\n### Market Data Templates\n\nThe `rb3` package uses a template system to standardize the downloading\nand processing of different data types. To see available templates:\n\n``` r\nlibrary(tidyverse)\nlibrary(bizdays)\nlibrary(rb3)\n\n# List available templates\nlist_templates()\n#\u003e # A tibble: 9 × 2\n#\u003e   Template                         Description                                  \n#\u003e   \u003cchr\u003e                            \u003cchr\u003e                                        \n#\u003e 1 b3-bvbg-086                      Arquivo de Preços de Mercado - BVBG-086      \n#\u003e 2 b3-cotahist-daily                Cotações Históricas do Pregão de Ações - Arq…\n#\u003e 3 b3-cotahist-yearly               Cotações Históricas do Pregão de Ações - Arq…\n#\u003e 4 b3-futures-settlement-prices     Preços de Ajustes Diários de Contratos Futur…\n#\u003e 5 b3-indexes-composition           Composição dos índices da B3                 \n#\u003e 6 b3-indexes-current-portfolio     Carteira teórica corrente dos índices da B3 …\n#\u003e 7 b3-indexes-historical-data       Dados históricos e estatísticas dos índices …\n#\u003e 8 b3-indexes-theoretical-portfolio Carteira Teórica dos índices da B3 com pesos…\n#\u003e 9 b3-reference-rates               Taxas referenciais\n```\n\n### Downloading Market Data\n\nThe main function for fetching data is `fetch_marketdata()`, which\ndownloads data based on a template and parameters:\n\n``` r\n# Download yield curve data for specific dates\nfetch_marketdata(\"b3-reference-rates\",\n  refdate = as.Date(\"2024-01-31\"),\n  curve_name = \"PRE\"\n)\n\n# Download futures settlement prices\nfetch_marketdata(\"b3-futures-settlement-prices\",\n  refdate = as.Date(\"2024-01-31\")\n)\n\n# Download yearly COTAHIST files\nfetch_marketdata(\"b3-cotahist-yearly\", year = 2023)\n```\n\n### Working with Historical Equity Data\n\n``` r\n# Access the data\nch \u003c- cotahist_get(\"yearly\")\n\n# Filter for stocks\neq \u003c- ch |\u003e\n  filter(year(refdate) == 2023) |\u003e\n  cotahist_filter_equity() |\u003e\n  collect()\n```\n\n``` r\n# Get top 10 most traded stocks\nsymbols \u003c- eq |\u003e\n  group_by(symbol) |\u003e\n  summarise(volume = sum(volume)) |\u003e\n  arrange(desc(volume)) |\u003e\n  head(10) |\u003e\n  pull(symbol)\n\n# show top 10 most traded stocks\nsymbols\n#\u003e  [1] \"VALE3\" \"PETR4\" \"ITUB4\" \"BBDC4\" \"BBAS3\" \"B3SA3\" \"PRIO3\" \"PETR3\" \"RENT3\"\n#\u003e [10] \"MGLU3\"\n```\n\n``` r\n# Plot the most traded stocks grouped by month\neq |\u003e\n  filter(symbol %in% symbols) |\u003e\n  mutate(refdate = floor_date(refdate, \"month\")) |\u003e\n  group_by(refdate, symbol) |\u003e\n  summarise(volume = sum(volume)) |\u003e\n  # Plot\n  ggplot(aes(x = refdate, y = volume, color = symbol)) +\n  geom_line() +\n  labs(\n    title = \"Top 10 Most Traded Stocks in 2023\",\n    x = \"Date\",\n    y = \"Volume\"\n  ) +\n  scale_y_continuous(labels = scales::comma)\n#\u003e `summarise()` has grouped output by 'refdate'. You can override using the\n#\u003e `.groups` argument.\n```\n\n\u003cimg src=\"man/figures/README-plot-cotahist-1.png\" width=\"100%\" /\u003e\n\n### Yield Curve Analysis\n\n``` r\n# Get Brazilian nominal yield curve (PRE)\nyc_data \u003c- yc_brl_get() |\u003e\n  filter(refdate == \"2024-01-31\") |\u003e\n  collect()\n```\n\n``` r\n# Plot the yield curve\nggplot(yc_data, aes(x = forward_date, y = r_252)) +\n  geom_line() +\n  labs(\n    title = \"Brazilian Yield Curve (PRE)\",\n    x = \"Forward Date\",\n    y = \"Annual Interest Rate\"\n  ) +\n  scale_y_continuous(labels = scales::percent)\n```\n\n\u003cimg src=\"man/figures/README-plot-yc-1.png\" width=\"100%\" /\u003e\n\n### Futures Contracts\n\n``` r\n# Get futures settlement prices\nfutures_data \u003c- futures_get() |\u003e\n  filter(commodity == \"DI1\") |\u003e\n  collect()\n```\n\n``` r\n# Calculate implied rates\ndi1_futures \u003c- futures_data |\u003e\n  mutate(\n    maturity_date = maturitycode2date(maturity_code),\n    business_days = bizdays(refdate, maturity_date, \"Brazil/ANBIMA\"),\n    implied_rate = (100000 / price)^(252 / business_days) - 1\n  )\n\n# Plot the implied rates\nggplot(di1_futures, aes(x = maturity_date, y = implied_rate)) +\n  geom_line() +\n  geom_point() +\n  labs(\n    title = \"Implied Rates for DI1 Futures\",\n    x = \"Maturity Date\",\n    y = \"Implied Rate\"\n  ) +\n  scale_y_continuous(labels = scales::percent)\n```\n\n\u003cimg src=\"man/figures/README-plot-futures-1.png\" width=\"100%\" /\u003e\n\n## Documentation\n\nFor comprehensive documentation and examples, visit:\n\n- [Package Website](https://ropensci.github.io/rb3/)\n- Vignettes (in-depth tutorials):\n  - [Getting\n    Started](https://ropensci.github.io/rb3/articles/Getting-started.html)\n  - [Fetching Historical Equity\n    Data](https://ropensci.github.io/rb3/articles/Fetching-historical-equity-data.html)\n  - [Analyzing B3 Index\n    Data](https://ropensci.github.io/rb3/articles/Fetching-historical-index-data.html)\n  - [How to Compute Historical Rates from B3 Future\n    Prices](https://ropensci.github.io/rb3/articles/Fetching-historical-future-rates.html)\n  - [Fetching B3 Yield\n    Curves](https://ropensci.github.io/rb3/articles/Fetching-historical-yield-curve.html)\n\n## Citation\n\nIf you use `rb3` in your research, please cite it:\n\n    To cite rb3 in publications use:\n\n      Download and parse public files released by B3 and convert them into\n      useful formats and data structures common to data analysis\n      practitioners.\n\n    A BibTeX entry for LaTeX users is\n\n      @Manual{rb3-package,\n        title = {Download and Parse Public Data Released by B3 Exchange},\n        author = {Wilson Freitas and Marcelo Perlin},\n        year = {2023},\n        note = {R package version 0.0.8},\n        url = {https://github.com/ropensci/rb3},\n      }\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Frb3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fropensci%2Frb3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fropensci%2Frb3/lists"}