Git Product home page Git Product logo

rbcb's Introduction

rbcb

R-CMD-check Codecov test coverage

An interface to structure the information provided by the Brazilian Central Bank. This package interfaces the Brazilian Central Bank web services to provide data already formatted into R’s data structures.

Install

From CRAN:

install.packages("rbcb")

From github using remotes:

remotes::install_github('wilsonfreitas/rbcb')

Features

Usage

Load the package:

library(rbcb)

The get_series function

Download the series by calling rbcb::get_series and pass the time series code is as the first argument. For example, let’s download the USDBRL time series which code is 1.

rbcb::get_series(c(USDBRL = 1))
#> # A tibble: 9,434 x 2
#>    date       USDBRL
#>    <date>      <dbl>
#>  1 1984-11-28   2828
#>  2 1984-11-29   2828
#>  3 1984-11-30   2881
#>  4 1984-12-03   2881
#>  5 1984-12-04   2881
#>  6 1984-12-05   2923
#>  7 1984-12-06   2923
#>  8 1984-12-07   2923
#>  9 1984-12-10   2965
#> 10 1984-12-11   2965
#> # ... with 9,424 more rows

Note that this series starts at 1984 and has approximately 8000 rows. Also note that you can name the downloaded series by passing a named vector in the code argument. To download recent values you should use the argument last = N, see below.

rbcb::get_series(c(USDBRL = 1), last = 10)
#> # A tibble: 10 x 2
#>    date       USDBRL
#>    <date>      <dbl>
#>  1 2022-07-12   5.41
#>  2 2022-07-13   5.40
#>  3 2022-07-14   5.46
#>  4 2022-07-15   5.40
#>  5 2022-07-18   5.37
#>  6 2022-07-19   5.39
#>  7 2022-07-20   5.43
#>  8 2022-07-21   5.48
#>  9 2022-07-22   5.45
#> 10 2022-07-25   5.41

The series can be downloaded in many different types: tibble, xts, ts or data.frame, but the default is tibble. See the next example where the Brazilian Broad Consumer Price Index (IPCA) is downloaded as xts object.

rbcb::get_series(c(IPCA = 433), last = 12, as = "xts")
#>            IPCA
#> 2021-07-01 0.96
#> 2021-08-01 0.87
#> 2021-09-01 1.16
#> 2021-10-01 1.25
#> 2021-11-01 0.95
#> 2021-12-01 0.73
#> 2022-01-01 0.54
#> 2022-02-01 1.01
#> 2022-03-01 1.62
#> 2022-04-01 1.06
#> 2022-05-01 0.47
#> 2022-06-01 0.67

or as a ts object.

rbcb::get_series(c(IPCA = 433), last = 12, as = "ts")
#>       Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec
#> 2021                               0.96 0.87 1.16 1.25 0.95 0.73
#> 2022 0.54 1.01 1.62 1.06 0.47 0.67

Multiple series can be downloaded at once by passing a named vector with the series codes. The return is a named list with the downloaded series.

rbcb::get_series(c(IPCA = 433, IGPM = 189), last = 12, as = "ts")
#> $IPCA
#>       Jan  Feb  Mar  Apr  May  Jun  Jul  Aug  Sep  Oct  Nov  Dec
#> 2021                               0.96 0.87 1.16 1.25 0.95 0.73
#> 2022 0.54 1.01 1.62 1.06 0.47 0.67                              
#> 
#> $IGPM
#>        Jan   Feb   Mar   Apr   May   Jun   Jul   Aug   Sep   Oct   Nov   Dec
#> 2021                                      0.78  0.66 -0.64  0.64  0.02  0.87
#> 2022  1.82  1.83  1.74  1.41  0.52  0.59

Market expectations

The function get_market_expectations returns market expectations discussed in the Focus Report that summarizes the statistics calculated from expectations collected from market practitioners.

The first argument type accepts the following values:

  • annual: annual expectations
  • quarterly: quarterly expectations
  • monthly: monthly expectations
  • top5s-monthly: monthly expectations for top 5 indicators
  • top5s-annual: annual expectations for top 5 indicators
  • inflation-12-months: inflation expectations for the next 12 months
  • institutions: market expectations informed by financial institutions

The example below shows how to download IPCA’s monthly expectations.

rbcb::get_market_expectations("monthly", "IPCA", end_date = "2018-01-31", `$top` = 5)
#> # A tibble: 5 x 10
#>   Indicador Data       DataReferencia Media Mediana DesvioPadrao Minimo Maximo numeroRespondentes baseCalculo
#>   <chr>     <date>     <chr>          <dbl>   <dbl>        <dbl>  <dbl>  <dbl>              <int>       <int>
#> 1 IPCA      2018-01-31 06/2019         0.21    0.2          0.07   0.13   0.36                 14           1
#> 2 IPCA      2018-01-31 06/2019         0.2     0.2          0.1   -0.3    0.36                 43           0
#> 3 IPCA      2018-01-31 05/2019         0.31    0.29         0.06   0.22   0.43                 19           1
#> 4 IPCA      2018-01-31 05/2019         0.31    0.3          0.06   0.15   0.45                 55           0
#> 5 IPCA      2018-01-31 04/2019         0.38    0.39         0.1    0.16   0.61                 20           1

OLINDA API for currency rates

Use currency functions to download currency rates from the BCB OLINDA API.

olinda_list_currencies()
#>    symbol                     name currency_type
#> 1     AUD        Dólar australiano             B
#> 2     CAD          Dólar canadense             A
#> 3     CHF             Franco suíço             A
#> 4     DKK       Coroa dinamarquesa             A
#> 5     EUR                     Euro             B
#> 6     GBP          Libra Esterlina             B
#> 7     JPY                     Iene             A
#> 8     NOK         Coroa norueguesa             A
#> 9     SEK              Coroa sueca             A
#> 10    USD Dólar dos Estados Unidos             A

Use olinda_get_currency function to download data from specific currency by the currency symbol.

olinda_get_currency("USD", "2017-03-01", "2017-03-03")
#> # A tibble: 13 x 3
#>    datetime              bid   ask
#>    <dttm>              <dbl> <dbl>
#>  1 2017-03-01 14:37:41  3.10  3.10
#>  2 2017-03-01 15:37:01  3.10  3.10
#>  3 2017-03-01 15:37:01  3.10  3.10
#>  4 2017-03-02 10:04:33  3.11  3.11
#>  5 2017-03-02 11:07:36  3.10  3.10
#>  6 2017-03-02 12:10:41  3.12  3.12
#>  7 2017-03-02 13:06:27  3.12  3.12
#>  8 2017-03-02 13:06:27  3.11  3.11
#>  9 2017-03-03 10:10:38  3.13  3.13
#> 10 2017-03-03 11:10:48  3.13  3.13
#> 11 2017-03-03 12:07:35  3.14  3.14
#> 12 2017-03-03 13:07:10  3.14  3.14
#> 13 2017-03-03 13:07:10  3.14  3.14

The rates come quoted in BRL, so 3.10 is worth 1 USD in BRL.

Parity values

Type A currencies have parity values quoted in USD (1 CURRENCY in USD).

olinda_get_currency("CAD", "2017-03-01", "2017-03-01")
#> # A tibble: 3 x 3
#>   datetime              bid   ask
#>   <dttm>              <dbl> <dbl>
#> 1 2017-03-01 14:37:41  2.32  2.32
#> 2 2017-03-01 15:37:01  2.32  2.32
#> 3 2017-03-01 15:37:01  2.32  2.32
olinda_get_currency("CAD", "2017-03-01", "2017-03-01", parity = TRUE)
#> # A tibble: 3 x 3
#>   datetime              bid   ask
#>   <dttm>              <dbl> <dbl>
#> 1 2017-03-01 14:37:41  1.33  1.33
#> 2 2017-03-01 15:37:01  1.33  1.33
#> 3 2017-03-01 15:37:01  1.33  1.33

Type B currencies have parity values as 1 USD in CURRENCY, see AUD, for example.

olinda_get_currency("AUD", "2017-03-01", "2017-03-01")
#> # A tibble: 3 x 3
#>   datetime              bid   ask
#>   <dttm>              <dbl> <dbl>
#> 1 2017-03-01 14:37:41  2.38  2.38
#> 2 2017-03-01 15:37:01  2.38  2.38
#> 3 2017-03-01 15:37:01  2.38  2.38
olinda_get_currency("AUD", "2017-03-01", "2017-03-01", parity = TRUE)
#> # A tibble: 3 x 3
#>   datetime              bid   ask
#>   <dttm>              <dbl> <dbl>
#> 1 2017-03-01 14:37:41 0.768 0.768
#> 2 2017-03-01 15:37:01 0.767 0.768
#> 3 2017-03-01 15:37:01 0.767 0.768

Currency rates

Use currency functions to download currency rates from the BCB web site.

rbcb::get_currency("USD", "2017-03-01", "2017-03-10")
#> # A tibble: 8 x 3
#>   date         bid   ask
#>   <date>     <dbl> <dbl>
#> 1 2017-03-01  3.10  3.10
#> 2 2017-03-02  3.11  3.11
#> 3 2017-03-03  3.14  3.14
#> 4 2017-03-06  3.11  3.11
#> 5 2017-03-07  3.12  3.12
#> 6 2017-03-08  3.15  3.15
#> 7 2017-03-09  3.17  3.17
#> 8 2017-03-10  3.16  3.16

The rates come quoted in BRL, so 3.0970 is worth 1 USD in BRL.

All currency time series have an attribute called symbol that stores its own currency name.

attr(rbcb::get_currency("USD", "2017-03-01", "2017-03-10"), "symbol")
#> [1] "USD"

Trying another currency.

get_currency("JPY", "2017-03-01", "2017-03-10") |> Ask()
#> # A tibble: 8 x 2
#>   date          JPY
#>   <date>      <dbl>
#> 1 2017-03-01 0.0273
#> 2 2017-03-02 0.0272
#> 3 2017-03-03 0.0274
#> 4 2017-03-06 0.0274
#> 5 2017-03-07 0.0274
#> 6 2017-03-08 0.0274
#> 7 2017-03-09 0.0276
#> 8 2017-03-10 0.0275

To see the avaliable currencies call list_currencies.

rbcb::list_currencies()
#> # A tibble: 218 x 5
#>    name                   code symbol country_name          country_code
#>    <chr>                 <dbl> <chr>  <chr>                        <dbl>
#>  1 AFEGANE AFEGANIST         5 AFN    AFEGANISTAO                    132
#>  2 RANDE/AFRICA SUL        785 ZAR    AFRICA DO SUL                 7560
#>  3 LEK ALBANIA REP         490 ALL    ALBANIA, REPUBLICA DA          175
#>  4 EURO                    978 EUR    ALEMANHA                       230
#>  5 KWANZA/ANGOLA           635 AOA    ANGOLA                         400
#>  6 DOLAR CARIBE ORIENTAL   215 XCD    ANGUILLA                       418
#>  7 DOLAR CARIBE ORIENTAL   215 XCD    ANTIGUA E BARBUDA              434
#>  8 RIAL/ARAB SAUDITA       820 SAR    ARABIA SAUDITA                 531
#>  9 DINAR ARGELINO           95 DZD    ARGELIA                        590
#> 10 PESO ARGENTINO          706 ARS    ARGENTINA                      639
#> # ... with 208 more rows

There are 216 currencies available.

Cross currency rates

The API provides a matrix with the relations between exchange rates, this is the matrix of cross currency rates. This is a square matrix with the all exchange rates between all currencies.

x <- rbcb::get_currency_cross_rates("2017-03-10")
dim(x)
#> [1] 156 156
# Since there are many currencies it is interesting to subset the matrix.
cr <- c("USD", "BRL", "EUR", "CAD")
x[cr, cr]
#>           USD    BRL       EUR       CAD
#> USD 1.0000000 3.1623 0.9380896 1.3465764
#> BRL 0.3162255 1.0000 0.2966479 0.4258218
#> EUR 1.0659963 3.3710 1.0000000 1.4354454
#> CAD 0.7426240 2.3484 0.6966479 1.0000000

The rates are quoted by its columns labels, so the numbers in the BRL column are worth one currency unit in BRL.

rbcb's People

Contributors

kimjoaoun avatar leoniedu avatar wilsonfreitas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rbcb's Issues

Series alias

The series are identified by numbers that aren't much clear or easy to remember when being used.
The series could have an alias or an alternative name and that name could be used to fetch data.

series_alias(USDBRL = 1, IPCA = 433)
get_series("USDBRL")
get_series("IPCA")

Set an attribute symbol for time series returned from get_currency

The get_currency function returns a data.frame or xts object with bid and ask columns. This object has no reference to the original currency symbol, so it might be lost if the assignment doesn't name the variable properly.
In order to correct that a new attribute containing the symbol must be set in the returned object.

Error in 'get_annual_market_expectations'

Hello!

I'm trying to get market expectations with the rbcb package, but i came across with this message:
"Error in .get_series(url) :
BCB API Request error cannot open the connection".

Can you help me?

Install in ubuntu 18.04

Hello,
Recently I've updated my OS and I can't install rbcb anymore. Any other way to install it? I've tried using install.packages('rbcb') and by .tar
Tkx

Unable to get monthly market expectations

Hi there. I'm receiving the following error when trying to get market expectations. I'm using the last version from HEAD.

> rbcb::get_monthly_market_expectations("IPCA")

Error in .get_series(url) : 
    BCB API Request error nπo Θ possφvel abrir a conexπo

Any ideas?

Erro ao buscar as séries

Olá!

Estou com um erro quando busco as séries:

rbcb::get_series(c(IPCA = 433, IGPM = 189), last = 12, as = "ts")
Error in .get_series(series_url(x, start_date, end_date, last)) :
BCB API Request error cannot open the connection

O que pode ser?

Timeout Connection

Hi!

The function get_top5s_annual_market_expectations and others like this are not working.

Error in .get_series(url) :
BCB API Request error cannot open the connection

Indic "Taxa de câmbio" is not avaliable

I have noticed that some indexes was changed on API, but when I try to get the monthly market expectations and use "Câmbio" (the newer version of "Taxa de câmbio") as indic value and it returns the error below:

Invalid indic argument: Câmbio

Could you help me?

OBS: When I tried to use "Taxa de câmbio" as indic it returned this warning message:

Warning messages: 1: Unknown or uninitialised column: date. 2: Unknown or uninitialised column: reference_month.

And the result dataframe is empty

Problema com API

Oi Wilson,

Seguinte, estou usando o rbcb mas desde ontem só retorna o seguinte erro:

Error in curl::curl_fetch_memory(url, handle = handle) :
SSL certificate problem: unable to get local issuer certificate

Imagino que o problema é no lado do BCB. Por acaso sabes como solucionar?

Segue meu código:

`
get.cdi.anual <- function(first.date = '2000-01-01', last.date = Sys.Date()) {
require(rbcb)
require(tidyverse)

cat('\nFetching CDI Anual')

my.code <- c(value = 4391)
df.cdi <- get_series(my.code, start_date = first.date,
end_date = last.date) %>%
mutate(series = 'CDI')

return(df.cdi)
}
`

Duplicated currencies in PTAX form

Hello,

First of all congratulations for the package, it's excellent!

I was using the package to retrieve time series for all currencies in a loop, and I noticed that there is a problem when it comes to querying certain currencies.

The function uses the PTAX forms and the select reference (ChkMoeda) to perform the query. The problem: there are, for some 3 letter ISO codes of the currency, more than one reference in the form list for the same currency.

Exemplifying, the following query does not quote for the period, even if there is some data in the PTAX:

mxn <- get_currency ("MXN", "2018-05-21", "2018-05-22")

Error in get_currency("MXN", "2018-05-21", "2018-05-22") : 
  BCB API returned error:Não existe informação para a pesquisa efetuada!

There are two references to PESO MEXICO in the form (I imagine an old one - no / in the text - that does not work and a recent one - with / in the text - that works), and I believe that when the parser is being made to translate 'MXN' for ChkMoeda from Mexico is catching the very first entry of PESO MEXICO (no /) that does not work. If you try the PTAX form with PESO/MEXICO, it works.

It seems to me that some adjustment in the following function would solve the question:

  id_list <- suppressMessages(currency_id_list())
  all_currencies <- suppressMessages(get_currency_list())
  x <- merge(id_list, all_currencies)
  x[x$symbol == symbol,]$id[1] # <<< aqui pode ter mais de uma ocorrência. Das que mapeei que tem duas, a primeira não funciona e a segunda sim
}

I did some workarounds but it's not cool to propose as a solution. Once I get a better time window I can make a proposal for improvement!

Thanks again for the package!

Error in get_currency

This error appears when running the get_currency: "BCB API returned error: • Moeda não cadastrada."

Example:
brl_usd <- get_currency('USD', t_1y, t) %>%
select(-bid) %>%
rename(brl_usd = 2)

brl_eur <- get_currency('EUR', t_1y, t) %>%
select(-bid) %>%
rename(brl_eur= 2)

brl_gbp <- get_currency('GBP', t_1y, t) %>%
select(-bid) %>%
rename(brl_libra = 2)

start_date and end_date only work together

The get_series arguments start_date and end_date only work when they are set together, but they are optional in the API.

For end_date there is a possible workaround, that is set Sys.Date() when this argument is necessary.
But, for start_date I have the date 1900-01-01 as a possible workaround.

Error on Installation: Unable to Collate and Parse

Hi there.

Has anyone experienced the error below while installing this through devtools::install_github?

* installing *source* package 'rbcb' ...
** using staged installation
** R
Error in parse(outFile) :
  C:/Users/raphael.coelho/AppData/Local/Temp/RtmpQJB2Lr/R.INSTALL3210597b5558/rbcb/R/rbcb_olinda_get_currencies.R:16:224: '>' inesperado
15: as.Date(end_date), "%m/%d/%Y")
16:   "https://olinda.bcb.gov.br/olinda/servico/PTAX/versao/v1/odata/CotacaoMoedaPeriodo(moeda=@moeda,dataInicial=@dataInicial,dataFinalCotacao=@dataFinalCotacao)?%%40moeda='%s'&%%40dataInicial='%

                      ^
ERROR: unable to collate and parse R files for package 'rbcb'

CRAN?

Aproveitando, notei que o pacote foi retirado do CRAN.

Foi decisão sua? Tens alguma perspectiva de retornar?

Sei que é chato aguentar as exigências do CRAN, mas o pacote fica mais fácil de acessar, principalmente para os alunos.

Mudança Expectativas de Mercado - Selic

BCB alterou a forma de divulgação da Selic no sistema de expectativas de mercado. Dessa forma, a previsão mensal parou de ser divulgada. Em seu lugar, entrou expectativas por reunião. Sendo assim, a função que puxa expectativas mensais para a selic parou de funcionar.

Essa é a primeira vez que relato um problema via github. Se não fiz da forma mais adequada, peço desculpas antecipadamente.

Parabéns pelo pacote - ajuda demais!

Set timeseries classes to implement special methods

Name the returned timeseries of functions:

  • get_series
  • get_currency

with an additional class named rbcbTimeSeries, for example.

This class can used to implement methods that:

  • return the currency name for data returned from get_currency
  • a special merge method to join returned time series

error in get_currency

whenever I try to use the function get_currency all I can get is:

Error in curl::curl_fetch_memory(url, handle = handle) :
Recv failure: Connection was reset

New interface to access series

Currently it has 2 functions

  • get_series: for SGS series
  • get_currency: for currency API

Since it has plans to have new interfaces implemented, a interesting approach is unify all interfaces into one single function

rbcb_get(...)

This function might be a generic and the objects represent the desired data.
Example:

rbcb_get(currecy('BRL'), start_date, end_date)              # uses currency API
rbcb_get(series(IBOVESPA = 7), start_date, end_date)  # uses SGS API

If in the future we have a search, the search could return these objects

brl <- rbcb_search('BRL')
rbcb_get(brl, start_date, end_date)

Create bid and ask helpers

The currency API returns the bid and ask columns.
Function helpers Bid and Ask would help returning these series instead of using subsetting operators.
Similar to what we have in quantmod with the helpers Cl, Op, ...

Date range specification

Instead of start_date and end_date a date range specification should be created, very similar to what we have with xts.

References:

  • xts
  • tidyquant
  • tsibble

One more option to get_series: "rownames"

The option rownames which defaults to FALSE could be implemented in get_series.
This option would create data.frames with dates as rownames instead of column, following the approach similar to xts

rbcb::get_series(16122, last = 24, name = "IPCA", as = "data.frame", rownames = TRUE)

Naming time series

To name time series with the get_series function the user has to use the argument name.

rbcb::get_series(2234, "2002-01-31", as = "xts", name = "cambio")

Another way to name series that I believe is more elegant and clean is by passing a named vector with the code. Example

rbcb::get_series(c(cambio = 2234), "2002-01-31", as = "xts")

This should have the same result.
In the future the name argument can be deprecated in favor of this new naming style.
This has a second advantage that is, get_series can return multiple series in the future and this naming style avoid inconsistencies.

Real state prices : IVG-R

Wilson, congrats for the package. It's a fantastic initiative.

I was wondering if it would be possible to incorporate in the package BCB's data on real state prices , which are organized by BCB as the IVG-R (Índice de Valores de Garantia de Imóveis Residenciais Financiados)

I've seen a few PDF reports on this index but I couldn't find IVG-R data on their website, though. I've already sent them an email requesting them to make this data publicly available on their open data portal.

best,

Rafael H M Pereira

Problema ao puxar a Selic

Boa tarde,

Faz alguns dias que um código (que sempre funcionou) parou de funcionar. A ideia é simples, só puxar a Selic:

end = '2022-02-01'
start = '2021-01-01'

selic_m <- rbcb::get_monthly_market_expectations("Selic",
start_date = start,
end_date = end)

Agora retorna um DF vazio. Talvez tenha a ver com o fato do BC ter mudado a estrutura da variável selic de mensal (com buracos) para "reuniões"? Saberia me dizer o que pode estar ocorrendo?

Muito obrigado!

rbcb aliases

It is annoying to remember these codes used in the get_series.
Maybe creating aliases would help with that.
These aliases can be create according to the use of the function get_series.
On the other hand they can be created manually.
The can be stored in the current directory or in the user home directory.

Error in get_series

Estou tentando baixar dados usando o get_series e recebo o seguinte erro:

Error in curl::curl_fetch_memory(url, handle = handle) :
LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to www3.bcb.gov.br:443

Já troquei de rede e tentei algumas coisas, mas continua assim. Alguma ideia do que pode ser?

Error when installing from devtools::install_github()

Hello everyone.

I can't install the package when using the command "devtools::install_github('wilsonfreitas/rbcb')". The message error is the following:

Warning messages:
1: In file.copy(savedcopy, lib, recursive = TRUE) :
problem copying C:\Users\gboechat\Documents\R\R-4.0.5\library\00LOCK\rlang\libs\x64\rlang.dll to C:\Users\gboechat\Documents\R\R-4.0.5\library\rlang\libs\x64\rlang.dll: Permission denied
2: In file.copy(savedcopy, lib, recursive = TRUE) :
problem copying C:\Users\gboechat\Documents\R\R-4.0.5\library\00LOCK\ellipsis\libs\x64\ellipsis.dll to C:\Users\gboechat\Documents\R\R-4.0.5\library\ellipsis\libs\x64\ellipsis.dll: Permission denied
3: In i.p(...) :
installation of package ‘C:/Users/gboechat/AppData/Local/Temp/Rtmpg9dslQ/file48f83e48396a/rbcb_0.1.6.tar.gz’ had non-zero exit status

Am I missing any extra step prior to installing it?

Kind regards,

start_date and end_date arguments

In order to be in conformity with other packages (quantmod, tidyquant, ...) the arguments start_date and end_date should be replaced with from and to.

The implemented version should bring a deprecated warning when the old arguments were used and suggesting that the new args should be used.

Functions to change:

  • get_series
  • get_currency
  • olinda_get_currency
  • expectations

The new function bcb_get should bring these new arguments.

Implement new interfaces

Estatísticas dos Sistemas de Liquidação de Títulos, Derivativos e Câmbio
https://olinda.bcb.gov.br/olinda/servico/ResumoCamaras_pt/versao/v1/documentacao

Expectativas de mercado para os principais indicadores macroeconômicos
https://olinda.bcb.gov.br/olinda/servico/Expectativas/versao/v1/documentacao

Taxas de Cambio DEPIN
https://dadosabertos.bcb.gov.br/organization/depin

Negociação de Títulos Federais no Mercado Secundário
https://dadosabertos.bcb.gov.br/dataset/negociacao-de-titulos-federais-no-mercado-secundario

Cronograma de vencimentos de títulos
https://dadosabertos.bcb.gov.br/dataset/cronograma-de-vencimentos-de-titulos

Change the column names in currency tables

The get_currency function returns a data.frame with columns bid and ask.

The columns should have the name of the currency: EUR.bid and EUR.ask.

With this feature we could return multiple series with one call.

Error when downloading market expectations

We have a problem with the server when downloading market expectations (the functions of the form get_xxx_market_expectations). It writes "Error in curl::curl_fetch_memory(url, handle = handle) :
Failure when receiving data from the peer". I think it is the same issue as in

https://stackoverflow.com/questions/51247912/jsonlite-suddenly-retunring-error-failure-when-receiving-data-from-the-peer/51520771#51520771

Maybe using readLines before the fromJSON function would fix it.

Problem on get_annual_market_expectations

Empty table is returned when trying to collect market expectations. It appears that the API is not returning data for some specific series.

In additional, the following warning is returned:

Warning messages: Unknown or uninitialised column: date.

Fetch multiple series at once

Once all series are indexed by dates it is easy to get all merged in the same data structure.
We can consider tibble, xts, data.frame, but ts can't.
Or instead of getting series merged the return should be a list with the series as its elements.

x <- get_series(c(1, 7, 433))
x[["1"]]
x[["7"]]
x[["433"]]

for named series

x <- get_series(c(DOL = 1, IBOV = 7, IPCA = 433))
x$DOL
x$IBOV
x$IPCA

Implement cache

The cache system can be implemented the say way I did in rb3 package, using tempdir.

Reference currency for get_currency

get_currency returns currencies quoted in BRL, but it is more usual USD quoted currencies.

An argument could be added to define the reference currency: BRL or USD (at first).

rbcb::get_currency(symbol, start_date, end_date, as, reference = c("USD", "BRL"))

New tidy argument

When downloading multiple series a new tidy argument should be interesting.

This call returns a list with two data.frames.

x <- rbcb::get_series(c(IBOVESPA = 7, USDBRL = 1), last = 5)

We could use a tidy argumento to return a tidy dataframe

x <- rbcb::get_series(c(IBOVESPA = 7, USDBRL = 1), last = 5, tidy = TRUE)

with the columns <date>, <variable>, <value>.
The tidy argument implies that the as argument should be ignored, because a tibble would always be returned.

This argument would also work with a single call instead of multiple series only.

Error fetching TR series

The 226 series refers to TR. This series has different layout and an error is being returned while fetching its data.

> rbcb::get_series(226, start_date = "2016-12-12", end_date = "2017-01-31")
Error in `[<-.data.frame`(`*tmp*`, del, value = NULL) : 
  missing values are not allowed in subscripted assignments of data frames
In addition: Warning message:
In eval(substitute(expr), e) : NAs introduced by coercion

This series has a different JSON.
The field datafim.

> rbcb::get_series(226, last = 5, as = "text")
[1] "[{\"data\":\"04/12/2017\",\"datafim\":\"04/01/2018\",\"valor\":\"0.0000\"},{\"data\":\"05/12/2017\",\"datafim\":\"05/01/2018\",\"valor\":\"0.0000\"},{\"data\":\"06/12/2017\",\"datafim\":\"06/01/2018\",\"valor\":\"0.0000\"},{\"data\":\"07/12/2017\",\"datafim\":\"07/01/2018\",\"valor\":\"0.0000\"},{\"data\":\"08/12/2017\",\"datafim\":\"08/01/2018\",\"valor\":\"0.0000\"}]"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.