ComeçarComece de graça

Introducing getSymbols()

The getSymbols() function from the quantmod package provides a consistent interface to import data from various sources into your workspace. By default, getSymbols() imports the data as a xts object.

This exercise will introduce you to getSymbols(). You will use it to import QQQ data from Yahoo! Finance. QQQ is an exchange-traded fund that tracks the Nasdaq 100 index, and Yahoo! Finance is the default data source for getSymbols().

You use the Symbols argument to specify the instrument (i.e. the ticker symbol) you want to import. Since Symbols is the first argument to getSymbols(), you usually just type the instrument name and omit Symbols =.

Este exercício faz parte do curso

Importing and Managing Financial Data in R

Ver curso

Instruções do exercício

  • Load the quantmod package using the library() function.
  • Now use getSymbols() to import QQQ data. Make sure the data gets assigned to QQQ (auto.assign = TRUE).
  • Use the str() function to view the structure of the QQQ object that getSymbols() created. Note the src and updated attributes.
  • Use the head() function to view the first few rows of QQQ.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

# Load the quantmod package


# Import QQQ data from Yahoo! Finance


# Look at the structure of the object getSymbols created


# Look at the first few rows of QQQ
Editar e executar o código