Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated currencies in PTAX form #19

Closed
sauloguerra opened this issue May 24, 2018 · 2 comments
Closed

Duplicated currencies in PTAX form #19

sauloguerra opened this issue May 24, 2018 · 2 comments

Comments

@sauloguerra
Copy link

sauloguerra commented May 24, 2018

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!

@wilsonfreitas
Copy link
Owner

Hi @sauloguerra

Thanks for reporting this problem and file this issue.
As you've mentioned rbcb doesn't use an API, it fetch the data from a FORM and this form has its own issues.
BCB has released a brand new API to access the currency data. I am working on it and, I hope, soon a new rbcb version will be released using this API.

wilsonfreitas added a commit that referenced this issue May 31, 2018
The PTAX form presents more than one currency id for the same currency.
For a few currencies (like MXN) the incorrect currency was being selected.
I implemented a workaround that gets the highest id.
This solution doesn't close this BUG, but for the great majority of currencies it works.

issue #19
@wilsonfreitas
Copy link
Owner

@sauloguerra I implemented a workaround and I guess that will work with the major currencies.

I was studying the API and I have seen that it won't solve this particular issue.

I am closing a new release by the end of this week so I guess this fix will be available on CRAN in the next week.

thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants