{"id":13416312,"url":"https://github.com/wilsonfreitas/rbcb","last_synced_at":"2025-10-22T04:08:19.027Z","repository":{"id":47501763,"uuid":"76243258","full_name":"wilsonfreitas/rbcb","owner":"wilsonfreitas","description":"R interface to Brazilian Central Bank web services","archived":false,"fork":false,"pushed_at":"2024-01-23T08:03:25.000Z","size":4555,"stargazers_count":90,"open_issues_count":8,"forks_count":20,"subscribers_count":14,"default_branch":"master","last_synced_at":"2024-09-29T14:16:11.419Z","etag":null,"topics":["brazilian-data","central-bank","central-banking","cross-currency-rates","currency-rates","download-currency-rates","exchange-rate","financial-data","r","rstats","time-series"],"latest_commit_sha":null,"homepage":"https://wilsonfreitas.github.io/rbcb/","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/wilsonfreitas.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"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":null}},"created_at":"2016-12-12T09:47:39.000Z","updated_at":"2024-08-24T07:16:35.000Z","dependencies_parsed_at":"2024-01-23T08:53:05.367Z","dependency_job_id":null,"html_url":"https://github.com/wilsonfreitas/rbcb","commit_stats":{"total_commits":216,"total_committers":6,"mean_commits":36.0,"dds":0.1620370370370371,"last_synced_commit":"2c52f4fe34b9d51f1575b3e07749b09ce9ea86a5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilsonfreitas%2Frbcb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilsonfreitas%2Frbcb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilsonfreitas%2Frbcb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wilsonfreitas%2Frbcb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wilsonfreitas","download_url":"https://codeload.github.com/wilsonfreitas/rbcb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243663514,"owners_count":20327300,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["brazilian-data","central-bank","central-banking","cross-currency-rates","currency-rates","download-currency-rates","exchange-rate","financial-data","r","rstats","time-series"],"created_at":"2024-07-30T21:00:56.909Z","updated_at":"2025-10-22T04:08:13.985Z","avatar_url":"https://github.com/wilsonfreitas.png","language":"R","funding_links":[],"categories":["R"],"sub_categories":["Data Sources"],"readme":"\n# rbcb \u003cimg src=\"man/figures/logo.png\" align=\"right\" width=\"120\" /\u003e\n\n\u003c!-- badges: start --\u003e\n\n[![](https://www.r-pkg.org/badges/version/rbcb)](https://cran.r-project.org/package=rbcb)\n[![](http://cranlogs.r-pkg.org/badges/last-month/rbcb)](https://cran.r-project.org/package=rbcb)\n[![R-CMD-check](https://github.com/wilsonfreitas/rbcb/actions/workflows/check-standard.yaml/badge.svg)](https://github.com/wilsonfreitas/rbcb/actions/workflows/check-standard.yaml)\n[![Codecov test\ncoverage](https://codecov.io/gh/wilsonfreitas/rbcb/branch/master/graph/badge.svg)](https://app.codecov.io/gh/wilsonfreitas/rbcb?branch=master)\n\u003c!-- badges: end --\u003e\n\nAn interface to structure the information provided by the [Brazilian\nCentral Bank](https://www.bcb.gov.br). This package interfaces the\n[Brazilian Central Bank web services](https://dadosabertos.bcb.gov.br)\nto provide data already formatted into R’s data structures.\n\n## Install\n\nFrom CRAN:\n\n``` r\ninstall.packages(\"rbcb\")\n```\n\nFrom github using remotes:\n\n``` r\nremotes::install_github('wilsonfreitas/rbcb')\n```\n\n## Features\n\n-   [rbcb](#rbcb)\n    -   [Install](#install)\n    -   [Features](#features)\n        -   [Usage](#usage)\n            -   [The `get_series` function](#the-get_series-function)\n            -   [Market expectations](#market-expectations)\n            -   [OLINDA API for currency\n                rates](#olinda-api-for-currency-rates)\n            -   [Currency rates](#currency-rates)\n            -   [Cross currency rates](#cross-currency-rates)\n\n### Usage\n\nLoad the package:\n\n``` r\nlibrary(rbcb)\n```\n\n#### The `get_series` function\n\n\u003ca name=\"single-series\"\u003e\u003c/a\u003e Download the series by calling\n`rbcb::get_series` and pass the time series code is as the first\nargument. For example, let’s download the USDBRL time series which code\nis `1`.\n\n``` r\nrbcb::get_series(c(USDBRL = 1))\n#\u003e # A tibble: 9,434 x 2\n#\u003e    date       USDBRL\n#\u003e    \u003cdate\u003e      \u003cdbl\u003e\n#\u003e  1 1984-11-28   2828\n#\u003e  2 1984-11-29   2828\n#\u003e  3 1984-11-30   2881\n#\u003e  4 1984-12-03   2881\n#\u003e  5 1984-12-04   2881\n#\u003e  6 1984-12-05   2923\n#\u003e  7 1984-12-06   2923\n#\u003e  8 1984-12-07   2923\n#\u003e  9 1984-12-10   2965\n#\u003e 10 1984-12-11   2965\n#\u003e # ... with 9,424 more rows\n```\n\nNote that this series starts at 1984 and has approximately 8000 rows.\nAlso note that you can name the downloaded series by passing a named\n`vector` in the `code` argument. To download recent values you should\nuse the argument `last = N`, see below.\n\n\u003ca name=\"tibble-objects\"\u003e\u003c/a\u003e\n\n``` r\nrbcb::get_series(c(USDBRL = 1), last = 10)\n#\u003e # A tibble: 10 x 2\n#\u003e    date       USDBRL\n#\u003e    \u003cdate\u003e      \u003cdbl\u003e\n#\u003e  1 2022-07-12   5.41\n#\u003e  2 2022-07-13   5.40\n#\u003e  3 2022-07-14   5.46\n#\u003e  4 2022-07-15   5.40\n#\u003e  5 2022-07-18   5.37\n#\u003e  6 2022-07-19   5.39\n#\u003e  7 2022-07-20   5.43\n#\u003e  8 2022-07-21   5.48\n#\u003e  9 2022-07-22   5.45\n#\u003e 10 2022-07-25   5.41\n```\n\n\u003ca name=\"download-types\"\u003e\u003c/a\u003e The series can be downloaded in many\ndifferent types: `tibble`, `xts`, `ts` or `data.frame`, but the default\nis `tibble`. See the next example where the Brazilian Broad Consumer\nPrice Index (IPCA) is downloaded as `xts` object.\n\n\u003ca name=\"xts-objects\"\u003e\u003c/a\u003e\n\n``` r\nrbcb::get_series(c(IPCA = 433), last = 12, as = \"xts\")\n#\u003e            IPCA\n#\u003e 2021-07-01 0.96\n#\u003e 2021-08-01 0.87\n#\u003e 2021-09-01 1.16\n#\u003e 2021-10-01 1.25\n#\u003e 2021-11-01 0.95\n#\u003e 2021-12-01 0.73\n#\u003e 2022-01-01 0.54\n#\u003e 2022-02-01 1.01\n#\u003e 2022-03-01 1.62\n#\u003e 2022-04-01 1.06\n#\u003e 2022-05-01 0.47\n#\u003e 2022-06-01 0.67\n```\n\nor as a `ts` object.\n\n\u003ca name=\"ts-objects\"\u003e\u003c/a\u003e\n\n``` r\nrbcb::get_series(c(IPCA = 433), last = 12, as = \"ts\")\n#\u003e       Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec\n#\u003e 2021                               0.96 0.87 1.16 1.25 0.95 0.73\n#\u003e 2022 0.54 1.01 1.62 1.06 0.47 0.67\n```\n\n\u003ca name=\"multiple-series\"\u003e\u003c/a\u003e Multiple series can be downloaded at once\nby passing a named vector with the series codes. The return is a named\nlist with the downloaded series.\n\n``` r\nrbcb::get_series(c(IPCA = 433, IGPM = 189), last = 12, as = \"ts\")\n#\u003e $IPCA\n#\u003e       Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec\n#\u003e 2021                               0.96 0.87 1.16 1.25 0.95 0.73\n#\u003e 2022 0.54 1.01 1.62 1.06 0.47 0.67                              \n#\u003e \n#\u003e $IGPM\n#\u003e        Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec\n#\u003e 2021                                      0.78  0.66 -0.64  0.64  0.02  0.87\n#\u003e 2022  1.82  1.83  1.74  1.41  0.52  0.59\n```\n\n#### Market expectations\n\n\u003ca name=\"market-expectations\"\u003e\u003c/a\u003e The function\n`get_market_expectations` returns market expectations discussed in the\nFocus Report that summarizes the statistics calculated from expectations\ncollected from market practitioners.\n\nThe first argument `type` accepts the following values:\n\n-   `annual`: annual expectations\n-   `quarterly`: quarterly expectations\n-   `monthly`: monthly expectations\n-   `top5s-monthly`: monthly expectations for top 5 indicators\n-   `top5s-annual`: annual expectations for top 5 indicators\n-   `inflation-12-months`: inflation expectations for the next 12 months\n-   `institutions`: market expectations informed by financial\n    institutions\n\nThe example below shows how to download IPCA’s monthly expectations.\n\n``` r\nrbcb::get_market_expectations(\"monthly\", \"IPCA\", end_date = \"2018-01-31\", `$top` = 5)\n#\u003e # A tibble: 5 x 10\n#\u003e   Indicador Data       DataReferencia Media Mediana DesvioPadrao Minimo Maximo numeroRespondentes baseCalculo\n#\u003e   \u003cchr\u003e     \u003cdate\u003e     \u003cchr\u003e          \u003cdbl\u003e   \u003cdbl\u003e        \u003cdbl\u003e  \u003cdbl\u003e  \u003cdbl\u003e              \u003cint\u003e       \u003cint\u003e\n#\u003e 1 IPCA      2018-01-31 06/2019         0.21    0.2          0.07   0.13   0.36                 14           1\n#\u003e 2 IPCA      2018-01-31 06/2019         0.2     0.2          0.1   -0.3    0.36                 43           0\n#\u003e 3 IPCA      2018-01-31 05/2019         0.31    0.29         0.06   0.22   0.43                 19           1\n#\u003e 4 IPCA      2018-01-31 05/2019         0.31    0.3          0.06   0.15   0.45                 55           0\n#\u003e 5 IPCA      2018-01-31 04/2019         0.38    0.39         0.1    0.16   0.61                 20           1\n```\n\n#### OLINDA API for currency rates\n\n\u003ca name=\"olinda-currency-rates\"\u003e\u003c/a\u003e Use currency functions to download\ncurrency rates from the BCB OLINDA API.\n\n``` r\nolinda_list_currencies()\n#\u003e    symbol                     name currency_type\n#\u003e 1     AUD        Dólar australiano             B\n#\u003e 2     CAD          Dólar canadense             A\n#\u003e 3     CHF             Franco suíço             A\n#\u003e 4     DKK       Coroa dinamarquesa             A\n#\u003e 5     EUR                     Euro             B\n#\u003e 6     GBP          Libra Esterlina             B\n#\u003e 7     JPY                     Iene             A\n#\u003e 8     NOK         Coroa norueguesa             A\n#\u003e 9     SEK              Coroa sueca             A\n#\u003e 10    USD Dólar dos Estados Unidos             A\n```\n\nUse `olinda_get_currency` function to download data from specific\ncurrency by the currency symbol.\n\n``` r\nolinda_get_currency(\"USD\", \"2017-03-01\", \"2017-03-03\")\n#\u003e # A tibble: 13 x 3\n#\u003e    datetime              bid   ask\n#\u003e    \u003cdttm\u003e              \u003cdbl\u003e \u003cdbl\u003e\n#\u003e  1 2017-03-01 14:37:41  3.10  3.10\n#\u003e  2 2017-03-01 15:37:01  3.10  3.10\n#\u003e  3 2017-03-01 15:37:01  3.10  3.10\n#\u003e  4 2017-03-02 10:04:33  3.11  3.11\n#\u003e  5 2017-03-02 11:07:36  3.10  3.10\n#\u003e  6 2017-03-02 12:10:41  3.12  3.12\n#\u003e  7 2017-03-02 13:06:27  3.12  3.12\n#\u003e  8 2017-03-02 13:06:27  3.11  3.11\n#\u003e  9 2017-03-03 10:10:38  3.13  3.13\n#\u003e 10 2017-03-03 11:10:48  3.13  3.13\n#\u003e 11 2017-03-03 12:07:35  3.14  3.14\n#\u003e 12 2017-03-03 13:07:10  3.14  3.14\n#\u003e 13 2017-03-03 13:07:10  3.14  3.14\n```\n\nThe rates come quoted in BRL, so 3.10 is worth 1 USD in BRL.\n\n**Parity values**\n\nType A currencies have parity values quoted in USD (1 CURRENCY in USD).\n\n``` r\nolinda_get_currency(\"CAD\", \"2017-03-01\", \"2017-03-01\")\n#\u003e # A tibble: 3 x 3\n#\u003e   datetime              bid   ask\n#\u003e   \u003cdttm\u003e              \u003cdbl\u003e \u003cdbl\u003e\n#\u003e 1 2017-03-01 14:37:41  2.32  2.32\n#\u003e 2 2017-03-01 15:37:01  2.32  2.32\n#\u003e 3 2017-03-01 15:37:01  2.32  2.32\n```\n\n``` r\nolinda_get_currency(\"CAD\", \"2017-03-01\", \"2017-03-01\", parity = TRUE)\n#\u003e # A tibble: 3 x 3\n#\u003e   datetime              bid   ask\n#\u003e   \u003cdttm\u003e              \u003cdbl\u003e \u003cdbl\u003e\n#\u003e 1 2017-03-01 14:37:41  1.33  1.33\n#\u003e 2 2017-03-01 15:37:01  1.33  1.33\n#\u003e 3 2017-03-01 15:37:01  1.33  1.33\n```\n\nType B currencies have parity values as 1 USD in CURRENCY, see AUD, for\nexample.\n\n``` r\nolinda_get_currency(\"AUD\", \"2017-03-01\", \"2017-03-01\")\n#\u003e # A tibble: 3 x 3\n#\u003e   datetime              bid   ask\n#\u003e   \u003cdttm\u003e              \u003cdbl\u003e \u003cdbl\u003e\n#\u003e 1 2017-03-01 14:37:41  2.38  2.38\n#\u003e 2 2017-03-01 15:37:01  2.38  2.38\n#\u003e 3 2017-03-01 15:37:01  2.38  2.38\n```\n\n``` r\nolinda_get_currency(\"AUD\", \"2017-03-01\", \"2017-03-01\", parity = TRUE)\n#\u003e # A tibble: 3 x 3\n#\u003e   datetime              bid   ask\n#\u003e   \u003cdttm\u003e              \u003cdbl\u003e \u003cdbl\u003e\n#\u003e 1 2017-03-01 14:37:41 0.768 0.768\n#\u003e 2 2017-03-01 15:37:01 0.767 0.768\n#\u003e 3 2017-03-01 15:37:01 0.767 0.768\n```\n\n#### Currency rates\n\n\u003ca name=\"currency-rates\"\u003e\u003c/a\u003e Use currency functions to download\ncurrency rates from the BCB web site.\n\n``` r\nrbcb::get_currency(\"USD\", \"2017-03-01\", \"2017-03-10\")\n#\u003e # A tibble: 8 x 3\n#\u003e   date         bid   ask\n#\u003e   \u003cdate\u003e     \u003cdbl\u003e \u003cdbl\u003e\n#\u003e 1 2017-03-01  3.10  3.10\n#\u003e 2 2017-03-02  3.11  3.11\n#\u003e 3 2017-03-03  3.14  3.14\n#\u003e 4 2017-03-06  3.11  3.11\n#\u003e 5 2017-03-07  3.12  3.12\n#\u003e 6 2017-03-08  3.15  3.15\n#\u003e 7 2017-03-09  3.17  3.17\n#\u003e 8 2017-03-10  3.16  3.16\n```\n\nThe rates come quoted in BRL, so 3.0970 is worth 1 USD in BRL.\n\nAll currency time series have an attribute called `symbol` that stores\nits own currency name.\n\n``` r\nattr(rbcb::get_currency(\"USD\", \"2017-03-01\", \"2017-03-10\"), \"symbol\")\n#\u003e [1] \"USD\"\n```\n\nTrying another currency.\n\n``` r\nget_currency(\"JPY\", \"2017-03-01\", \"2017-03-10\") |\u003e Ask()\n#\u003e # A tibble: 8 x 2\n#\u003e   date          JPY\n#\u003e   \u003cdate\u003e      \u003cdbl\u003e\n#\u003e 1 2017-03-01 0.0273\n#\u003e 2 2017-03-02 0.0272\n#\u003e 3 2017-03-03 0.0274\n#\u003e 4 2017-03-06 0.0274\n#\u003e 5 2017-03-07 0.0274\n#\u003e 6 2017-03-08 0.0274\n#\u003e 7 2017-03-09 0.0276\n#\u003e 8 2017-03-10 0.0275\n```\n\nTo see the avaliable currencies call `list_currencies`.\n\n``` r\nrbcb::list_currencies()\n#\u003e # A tibble: 218 x 5\n#\u003e    name                   code symbol country_name          country_code\n#\u003e    \u003cchr\u003e                 \u003cdbl\u003e \u003cchr\u003e  \u003cchr\u003e                        \u003cdbl\u003e\n#\u003e  1 AFEGANE AFEGANIST         5 AFN    AFEGANISTAO                    132\n#\u003e  2 RANDE/AFRICA SUL        785 ZAR    AFRICA DO SUL                 7560\n#\u003e  3 LEK ALBANIA REP         490 ALL    ALBANIA, REPUBLICA DA          175\n#\u003e  4 EURO                    978 EUR    ALEMANHA                       230\n#\u003e  5 KWANZA/ANGOLA           635 AOA    ANGOLA                         400\n#\u003e  6 DOLAR CARIBE ORIENTAL   215 XCD    ANGUILLA                       418\n#\u003e  7 DOLAR CARIBE ORIENTAL   215 XCD    ANTIGUA E BARBUDA              434\n#\u003e  8 RIAL/ARAB SAUDITA       820 SAR    ARABIA SAUDITA                 531\n#\u003e  9 DINAR ARGELINO           95 DZD    ARGELIA                        590\n#\u003e 10 PESO ARGENTINO          706 ARS    ARGENTINA                      639\n#\u003e # ... with 208 more rows\n```\n\nThere are 216 currencies available.\n\n#### Cross currency rates\n\n\u003ca name=\"cross-currency-rates\"\u003e\u003c/a\u003e The API provides a matrix with the\nrelations between exchange rates, this is the matrix of cross currency\nrates. This is a square matrix with the all exchange rates between all\ncurrencies.\n\n``` r\nx \u003c- rbcb::get_currency_cross_rates(\"2017-03-10\")\ndim(x)\n#\u003e [1] 156 156\n```\n\n``` r\n# Since there are many currencies it is interesting to subset the matrix.\ncr \u003c- c(\"USD\", \"BRL\", \"EUR\", \"CAD\")\nx[cr, cr]\n#\u003e           USD    BRL       EUR       CAD\n#\u003e USD 1.0000000 3.1623 0.9380896 1.3465764\n#\u003e BRL 0.3162255 1.0000 0.2966479 0.4258218\n#\u003e EUR 1.0659963 3.3710 1.0000000 1.4354454\n#\u003e CAD 0.7426240 2.3484 0.6966479 1.0000000\n```\n\nThe rates are quoted by its columns labels, so the numbers in the BRL\ncolumn are worth one currency unit in BRL.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilsonfreitas%2Frbcb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilsonfreitas%2Frbcb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilsonfreitas%2Frbcb/lists"}