stevecondylios / priceR

Economics and Pricing in R
https://stevecondylios.github.io/priceR/
Other
59 stars 7 forks source link

Incorrect Data for historical exchange rate for BTN #21

Open tanyanchongDA opened 4 years ago

tanyanchongDA commented 4 years ago

Hi,

I have just started using your package to get historical FX data. I must say the package is awesome, rather than an exhausting scraping of online pages to get all the FX.

On the other hand, I am trying to get exchange rates for BTN/USD and BTN/SGD pairing. However, it seems that the data doesn't seem correct. BTN/SGD has an exchange rate way lower than 0.001, but it is shown as above 1 until 10/5/2020 when it is shown as 1 the correct values. I couldn't verify at the ECB Currency Converter though.

May I know what could be the cause?

Thank you very much in advance!

stevecondylios commented 4 years ago

Hi, thanks for letting me know (and glad you like the package!)

Just before I look into this, can I double-check that we are looking at the right currency code (some are very similar, and can therefore cause understandable confusion).

library(priceR)
library(tidyverse)

currencies() %>% 
  filter(code %>% substr(1,2) == "BT")

#          description code
# 1            Bitcoin  BTC
# 2 Bhutanese Ngultrum  BTN

That is, I suspect this is what you're after?


options(scipen = 999)

bitcoin <- historical_exchange_rates("SGD", to = "BTC",
                          start_date = "2010-01-01", end_date = "2020-06-30")

bitcoin %>% tail
           date one_SGD_equivalent_to_x_BTC
3829 2020-06-25                    0.000078
3830 2020-06-26                    0.000078
3831 2020-06-27                    0.000080
3832 2020-06-28                    0.000079
3833 2020-06-29                    0.000078
3834 2020-06-30                    0.000079

If there's still an issue, let me know and I'll look into it.

tanyanchongDA commented 4 years ago

Hi Steve!

Thanks for the reply! I am actually looking at Bhutanese Ngultrum. I have pasted my source code here, and I actually see this in ggplot.

library(tidyverse)
library(priceR)

dataset <- historical_exchange_rates("BTN", to = "SGD", start_date = as.Date("2010-01-01"),
                          end_date = Sys.Date()) 

colnames(dataset) <- c("Date","Rates")

dataset %>%
  mutate_at(vars(Date),~as.Date(.)) %>%
  ggplot(aes(x=Date,y=Rates)) +
  geom_line() +
  theme_classic()

So after plotting on ggplot, this is what I have seen.

image

It is the same for BTN/USD pair as well.

image

Looking forward to hear from you!

tanyanchongDA commented 4 years ago

I am also seeing the same thing for IDR/SGD, THB/SGD, MYR/SGD and TWD/SGD pairs as well before 30/11/2003. I checked with the ECB Currency Converter and it gave correct results.

stevecondylios commented 4 years ago

I see it now in BTN to SGD.

historical_exchange_rates("BTN", to = "SGD", start_date = "2020-04-28",
                          end_date = "2020-05-03") 

#         date one_BTN_equivalent_to_x_SGD
# 1 2020-04-28                    1.537000
# 2 2020-04-29                    1.534500
# 3 2020-04-30                    1.533800
# 4 2020-05-01                    0.018711
# 5 2020-05-02                    0.018855
# 6 2020-05-03                    0.018855

And with BTN to TBH

historical_exchange_rates("BTN", to = "TBH", start_date = "2020-04-28",
                          end_date = "2020-05-03")

        date one_BTN_equivalent_to_x_TBH
1 2020-04-28                    3.973800
2 2020-04-29                    3.976100
3 2020-04-30                    3.993200
4 2020-05-01                    0.048693
5 2020-05-02                    0.048930
6 2020-05-03                    0.048930

Have you noticed anything regarding currency pairs that don't include BTN, or with any dates outside of the range 2020-04-30 to 2020-05-01?

Thanks for reporting. I will report upstream.

tanyanchongDA commented 4 years ago

Thanks! It is awesome!

Yeah. As I indicated in one of the post, IDR/SGD, THB/SGD, MYR/SGD and TWD/SGD pairs are a bit weird before 30/11/2003.