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 =
.
This is a part of the course
“Importing and Managing Financial Data in R”
Exercise instructions
- Load the quantmod package using the
library()
function. - Now use
getSymbols()
to import QQQ data. Make sure the data gets assigned toQQQ
(auto.assign = TRUE
). - Use the
str()
function to view the structure of theQQQ
object thatgetSymbols()
created. Note thesrc
andupdated
attributes. - Use the
head()
function to view the first few rows ofQQQ
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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
This exercise is part of the course
Importing and Managing Financial Data in R
Learn how to access financial data from local files as well as from internet sources.
A wealth of financial and economic data are available online. Learn how getSymbols() and Quandl() make it easy to access data from a variety of sources.
Exercise 1: Welcome to the course!Exercise 2: Introducing getSymbols()Exercise 3: Data sourcesExercise 4: Make getSymbols() return the data it retrievesExercise 5: Finding data from internet sourcesExercise 6: Find stock ticker from Yahoo FinanceExercise 7: Download exchange rate data from OandaWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.