Welcome to the course!

Importing and Managing Financial Data in R

Joshua Ulrich

Quantitative Analyst & quantmod Co-Author and Maintainer

About me

  • Author and/or maintainer of several packages
    • TTR, xts, quantmod, blotter, quantstrat
  • R/Finance Conference Organizing Committee
  • St. Louis R User Group
Importing and Managing Financial Data in R

What is getSymbols()?

  • Provides access to multiple data sources
  • Returns xts object by default
  • Can import data two ways:
    • Return data like an ordinary function
    • Create an object like load() does in base R
Importing and Managing Financial Data in R
getSymbols(Symbols = "AAPL", src = "yahoo")
"AAPL"
getSymbols("AAPL")
"AAPL"
head(AAPL)
           AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2007-01-03     86.29     86.58    81.90      83.80   309579900      10.85709
2007-01-04     84.05     85.95    83.82      85.66   211815100      11.09807
2007-01-05     85.77     86.20    84.40      85.05   208685400      11.01904
2007-01-08     85.96     86.53    85.28      85.47   199276700      11.07345
2007-01-09     86.45     92.98    85.15      92.57   837324600      11.99333
2007-01-10     94.75     97.80    93.45      97.00   738220000      12.56728
Importing and Managing Financial Data in R

getSymbols() data sources

Yahoo! Finance Yahoo Finance logo
Google Finance Google Finance logo
FRED FRED logo
Oanda OANDA logo
CSV CSV
Importing and Managing Financial Data in R

Other getSymbols() data sources

  • Yahoo! Finance Japan
  • MySQL
  • SQLite
  • RData
  • rds (created by saveRDS())
Importing and Managing Financial Data in R

getSymbols() example

# Load data like load()
getSymbols("AAPL", auto.assign = TRUE)
"AAPL"
head(AAPL, n = 3)
           AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2007-01-03     86.29     86.58    81.90      83.80   309579900      10.85709
2007-01-04     84.05     85.95    83.82      85.66   211815100      11.09807
2007-01-05     85.77     86.20    84.40      85.05   208685400      11.01904
Importing and Managing Financial Data in R

getSymbols() example

# Return data like a normal function
aapl <- getSymbols("AAPL", auto.assign = FALSE)
head(aapl, n = 3)
           AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
2007-01-03     86.29     86.58    81.90      83.80   309579900      10.85709
2007-01-04     84.05     85.95    83.82      85.66   211815100      11.09807
2007-01-05     85.77     86.20    84.40      85.05   208685400      11.01904
Importing and Managing Financial Data in R

Let's practice!

Importing and Managing Financial Data in R

Preparing Video For Download...