Importing and Managing Financial Data in R
Joshua Ulrich
Quantitative Analyst & quantmod Co-Author and Maintainer
TTR
, xts
, quantmod
, blotter
, quantstrat
xts
object by defaultload()
does in base RgetSymbols(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
Yahoo! Finance | ![]() |
Google Finance | ![]() |
FRED | ![]() |
Oanda | ![]() |
CSV | ![]() |
saveRDS()
)# 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
# 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