Download exchange rate data from Oanda
Oanda.com provides historical foreign exchange data for many currency pairs. Currency pairs are expressed as two currencies, the "base" and the "quote", separated by a "/". For example, the U.S. Dollar to Euro exchange rate would be "USD/EUR".
Note that getSymbols() will automatically convert "USD/EUR" to a valid name by removing the "/". For example, getSymbols("USD/EUR") would create an object named USDEUR.
Also, Oanda.com only provides 180 days of historical data. getSymbols() will warn and return as much data as possible if you request data from more than 180 days ago. You can use the from and to arguments to set a date range; both should be strings in "%Y-%m-%d" format (e.g. "2016-02-06").
Cet exercice fait partie du cours
Importing and Managing Financial Data in R
Instructions
- Create an object called
currency_pairwith the symbols for the British Pound and the Canadian Dollar so we can use this to get British Pound to Canadian Dollar exchange rate data.quantmod::oanda.currenciescontains a list of currencies provided by Oanda.com. - Use
getSymbols()to load data forcurrency_pair. Remember to specifysrc! - Use
str()to examine the datagetSymbols()created. Remember, it will remove the/! - Try to load data from 190 days ago to today. Remember that
Sys.Date()will give you today's date.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Create a currency_pair object
currency_pair <- "___/___"
# Load British Pound to Canadian Dollar exchange rate data
# Examine object using str()
# Try to load data from 190 days ago
getSymbols(___, from = Sys.Date() - ___, to = Sys.Date(), src = "___")