knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Usage of "exchangeratesr" - vignette

This vignette contains examples showing the usage of the eur and eurusds functions form the exchangeratesr package. In this example, my main goal is to visualize bitcoin prices and the amount sold each day using the binancer and ggplot2 packages.

library(binancer)
library(data.table)
coin_prices <- binance_klines('BTCUSDT', interval = '1d', limit = 45)

balance <- coin_prices[, .(date = as.Date(close_time), btcusd = close, usd_volume = volume)]
head(balance)

Now that we have the balances and the BTC price, we load the exchangeratesr package and use the eurusds function to import historical values of EURUSD exchange rates.

library(exchangeratesr)
rates <- eurusds(Sys.Date() - 45, Sys.Date())

setkey(balance, date)
setkey(rates, date)

balance <- rates[balance, roll = TRUE]
balance[, eur_volume := usd_volume * btcusd * eurusd,]
head(balance)

Finally, visualize the values for the last 45 days and use the eur function to format EUR values.

library(ggplot2)

ggplot(data = balance, aes(x = date, y = eur_volume)) +
  geom_line(color = 'blue') +
  scale_y_continuous() +
  theme_bw() +
  labs(title = 'Total BTC value in the last 45 days',
       x = 'date',
       y = 'value in EUR')


molnardan95/exchangeratesr documentation built on June 13, 2019, 7:48 a.m.