GetExchangeRates {shinyInvoice} | R Documentation |
Functions get_exchange_rates_symbol, try_exchange_rates_direct_and_indirect and GetExchangeRates
Description
get_exchange_rates_symbol: uses getSymbols
GetExchangeRates: uses getFX and getSymbols
Usage
GetExchangeRates(from_curr, to_curr, from_date, to_date = from_date)
get_exchange_rates_symbol(from_curr, to_curr, from_date, to_date = from_date)
try_exchange_rates_direct_and_indirect(date, from_curr, to_curr, tries = 8)
Arguments
from_curr |
character, currency symbol |
to_curr |
character, currency symbol |
from_date |
character, date |
to_date |
character, date |
date |
character, desired date |
tries |
numeric try how many days before desired date |
Value
data.frame
data.frame
numeric vector
References
Ryan JA, Ulrich JM (2023). quantmod: Quantitative Financial Modelling Framework. R package version 0.4.25, https://CRAN.R-project.org/package=quantmod.
Examples
from_curr <- c("CAD", "JPY", "USD")
to_curr <- c("USD", "USD", "EUR")
# get_exchange_rates_symbol and try_exchange_rates_direct_and_indirect
# use quantmod::getSymbols, which requires a working curl, as in:
if (requireNamespace("curl", quietly = TRUE)) {
con <- curl::curl(url = "https://hb.cran.dev/get", open = "r", handle = curl::new_handle())
print(con)
close(con)
}
# Success
recent_date <- as.character(Sys.Date() - 7)
GetExchangeRates(from_curr = from_curr, to_curr = to_curr, recent_date, recent_date)
# last date mismatch day
GetExchangeRates(from_curr = from_curr, to_curr = to_curr, "2023-10-27", "2023-10-30")
# weekend, warning, gets only FX, fails for getSymbols
# update this dates to less than 180 days!
GetExchangeRates(from_curr = from_curr, to_curr = to_curr, "2023-10-28", "2023-10-28")
GetExchangeRates(from_curr = from_curr, to_curr = to_curr, "2023-10-29", "2023-10-29")
GetExchangeRates(from_curr = from_curr, to_curr = to_curr, "2023-07-08", "2023-07-09")
# fails for FX, > 180 days
GetExchangeRates(from_curr = from_curr, to_curr = to_curr, "2023-04-03", "2023-04-05")
# failure for getSymbols, when none is USD
GetExchangeRates(from_curr = "BRL", to_curr = "COP", "2023-07-07")
# getSymbols success
get_exchange_rates_symbol(from_curr = from_curr, to_curr = to_curr, "2023-07-03", "2023-07-05")
# getSymbols > 180 days ok
get_exchange_rates_symbol(from_curr = from_curr, to_curr = to_curr, "2023-04-03", "2023-04-05")
# failure, weekend days
weekend_failure <- try(get_exchange_rates_symbol(
from_curr = from_curr,
to_curr = to_curr, "2023-07-08", "2023-07-09"
), silent = TRUE)
weekend_failure
# works
try_exchange_rates_direct_and_indirect("2023-07-08", from_curr, to_curr, tries = 8)
try_exchange_rates_direct_and_indirect("2023-07-08", "BRL", "USD", tries = 8)
try_exchange_rates_direct_and_indirect("2023-07-08", "USD", "BRL", tries = 8)
# works indirectly
recent_date <- as.character(Sys.Date() - 7)
try_exchange_rates_direct_and_indirect(recent_date, "COP", "BRL", tries = 8)
# works with FX only, provided, not greater than 180 days
GetExchangeRates(from_curr = "COP", to_curr = "BRL", recent_date)
[Package shinyInvoice version 0.0.5 Index]