Are there are any R packages/functions to get exchange rates in real time, e.g. from Google Finance? Would prefer to avoid RCurl or other parsers if something\'s already out
You could use historical_exchange_rates()
from the priceR library.
E.g. to get the daily AUD to USD exchange rate from 2010 to 2020:
# install.packages("priceR")
library(priceR)
cur <- historical_exchange_rates("AUD", to = "USD",
start_date = "2010-01-01", end_date = "2020-06-30")
tail(cur)
date one_AUD_equivalent_to_x_USD
2020-06-25 0.688899
2020-06-26 0.686340
2020-06-27 0.686340
2020-06-28 0.685910
2020-06-29 0.687335
2020-06-30 0.690166
dim(cur)
[1] 3834 2
# Plot USD vs AUD last 10 years
library(ggplot2)
library(tidyverse)
cur %>%
tail(365 * 10) %>%
rename(aud_to_usd = one_AUD_equivalent_to_x_USD) %>%
mutate(date = as.Date(date)) %>%
ggplot(aes(x = date, y = aud_to_usd, group = 1)) +
geom_line() +
geom_smooth(method = 'loess') +
theme(axis.title.x=element_blank(),
axis.ticks.x=element_blank()) +
scale_x_date(date_labels = "%Y", date_breaks = "1 year")