Set default data source for one symbol
Changing the default source for one instrument is useful if multiple sources use the same symbol for different instruments. For example, getSymbols("CP", src = "yahoo") would load Canadian Pacific Railway data from the New York Stock Exchange. But getSymbols("CP", src = "FRED") would load Corporate Profits After Tax from the U.S. Bureau of Economic Analysis.
You can use setSymbolLookup() to specify the default data source for an instrument. In this exercise, you will learn how to make getSymbols("CP") load the corporate profit data from FRED instead of the railway stock data from Yahoo Finance.
setSymbolLookup() can take any number of name = value pairs, where name is the symbol and value is a named list of getSymbols() arguments for that one symbol.
Cet exercice fait partie du cours
Importing and Managing Financial Data in R
Instructions
- Use
head()to look at the first few rows of data forCP, which has been loaded for you. - Complete the call to
setSymbolLookup()to use FRED as the source forCP. - Use
getSymbols()to load the data again. - Look at the first few rows of
CPand compare the output to the output from the first instruction.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Look at the first few rows of CP
# Set the source for CP to FRED
setSymbolLookup(___ = list(src = "___"))
# Load CP data again
# Look at the first few rows of CP