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.
This exercise is part of the course
Importing and Managing Financial Data in R
Exercise 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
CP
and compare the output to the output from the first instruction.
Hands-on interactive exercise
Have a go at this exercise by completing this sample 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