Find stock ticker from Yahoo Finance
You need the instrument identifier to import data from an internet data source. They can often be found on the data source website. In this exercise, you will search Yahoo Finance for the ticker symbol for Pfizer stock.
Note that some sources may not provide data for certain symbols, even if you can see the data displayed on their website in tables and/or charts. getSymbols()
will error if the data is not available for download.
This exercise is part of the course
Importing and Managing Financial Data in R
Exercise instructions
- Create an object called
symbol
from the three-letter Yahoo Finance ticker symbol for Pfizer stock. To find the symbol, go to Yahoo Finance and search for "Pfizer". Note that there are two parts to this ticker. We only need what comes before the period (the period and suffix specify other exchanges). - Use
getSymbols()
to import the data. - Use the
head()
function to view the first few rows of the object created bygetSymbols()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create an object containing the Pfizer ticker symbol
symbol <- "___"
# Use getSymbols to import the data for 'symbol'
# Look at the data in the object getSymbols created