ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Importing and Managing Financial Data in R

Ver curso

Instrucciones del ejercicio

  • Use head() to look at the first few rows of data for CP, which has been loaded for you.
  • Complete the call to setSymbolLookup() to use FRED as the source for CP.
  • 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.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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
Editar y ejecutar código