Aan de slagGa gratis aan de slag

Create valid names for multiple instruments

An earlier exercise taught you how to use setSymbolLookup() to set a default data source for getSymbols(). You can also use setSymbolLookup() to create a mapping between the instrument symbol and the name of the R object.

This is useful if you want to download data for a lot symbols that are not syntactically valid names, or symbols that have names that conflict with other R variable names.

An example of a name that conflicts is the symbol for AT&T's stock, T, which is often used as a short form for the logical value TRUE.

To change the name of a given symbol, arguments must be passed to setSymbolLookup() as a list, like so: setSymbolLookup(NEW_NAME = list(name = "OLD_NAME")).

Deze oefening maakt deel uit van de cursus

Importing and Managing Financial Data in R

Cursus bekijken

Oefeninstructies

  • Set the name for "BRK-A" to "BRK.A".
  • Set the name for "T" (AT&T) to "ATT".
  • Use one getSymbols() call to load data for both instruments using the new names you assigned to them.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Set name for BRK-A to BRK.A


# Set name for T to ATT
setSymbolLookup(___ = list(name = "___"))


# Load BRK.A and ATT data
getSymbols(c("___", "___"))
Code bewerken en uitvoeren