eur
and eurusds
functionsmy-vignette.Rmd
The goal of this vignette is to demonstrate how eur
and eurusds
functions can be applied by using them in Bitocoin report generation.
The daily volume and close prices of Bitcoins sold for “USDT” on Binance for the last 45 days can be fetched with the help of binance_klines
from the binancer
package:
The exchange rates can be fetched with the help of eurusds
function for specified dates:
Merge the tables by date. Note that the Foreign Exchange market is closed on holidays and weekends, therefore for the days with the missing exchange rate the latest rate available would be used.
# Merge the tables
BTC_45_days <- exchange_rates[BTC_45_days, roll = TRUE]
# Get the total value ein Euro
BTC_45_days[, value_eur := btcusd * volume * eurusd]
# Show first entires of the table
pandoc.table(head(BTC_45_days))
date | eurusd | btcusd | volume | value_eur |
---|---|---|---|---|
2019-04-15 | 0.8839 | 5025 | 29057 | 129064735 |
2019-04-16 | 0.8846 | 5174 | 24242 | 110944279 |
2019-04-17 | 0.8849 | 5203 | 23308 | 107304588 |
2019-04-18 | 0.8889 | 5258 | 22619 | 105726143 |
2019-04-19 | 0.8889 | 5259 | 24611 | 1.15e+08 |
2019-04-20 | 0.8889 | 5292 | 19169 | 90165944 |
Now, as all necessary information is fetched, the plot is created. Note the usage of eur
function in the last line: it formats numeric values on the Y-axis as Euros.
ggplot(BTC_45_days, aes(as.POSIXct(date), value_eur)) +
geom_line(aes(col = value_eur), size = 2) +
theme_bw() +
theme(axis.text.x = element_text(vjust = 0.5), panel.grid.major = element_line(colour = "darkgrey"),
legend.position = 'None') +
labs(x = '', y = '', title = 'Overall Value of Bitcoins Sold in EUR',
subtitle = paste0(date_format('%B %d')(date_from), ' - ', date_format('%B %d')(date_to), ', ',
date_format('%Y')(date_to))) +
scale_x_datetime(breaks = "5 day", labels = date_format("%d-%B"), minor_breaks = "1 day") +
scale_color_continuous(low = 'royalblue', high = 'olivedrab2') +
scale_y_continuous(labels = eur)