Importing and Managing Financial Data in R
Joshua Ulrich
Quantitative Analyst & quantmod Co-Author and Maintainer
head(DC)
DC.Open DC.High DC.Low DC.Close DC.Volume
2016-01-16 01:00:00 20.845 20.850 20.835 20.845 157
2016-01-16 02:00:00 20.845 20.850 20.835 20.845 214
2016-01-16 03:00:00 20.845 20.850 20.835 20.845 103
2016-01-16 04:00:00 20.845 20.855 20.835 20.845 180
2016-01-16 05:00:00 20.845 20.845 20.845 20.845 211
2016-01-16 06:00:00 20.845 20.845 20.840 20.845 35
Op()
- opening priceHi()
- high priceLo()
- low priceCl()
- close priceVo()
- traded volumeAd()
- adjusted close price# Open price
dc_open <- Op(DC)
head(dc_open, 4)
DC.Open
2016-01-16 01:00:00 20.84
2016-01-16 02:00:00 20.85
2016-01-16 03:00:00 20.85
2016-01-16 04:00:00 20.85
# High price
dc_high <- Hi(DC)
head(dc_high, 4)
DC.High
2016-01-16 01:00:00 20.85
2016-01-16 02:00:00 20.85
2016-01-16 03:00:00 20.85
2016-01-16 04:00:00 20.85
# Extract multiple columns
dc_ohlc <- OHLC(DC)
head(dc_ohlc)
DC.Open DC.High DC.Low DC.Close
2016-01-16 01:00:00 20.84 20.85 20.83 20.84
2016-01-16 02:00:00 20.85 20.85 20.83 20.85
2016-01-16 03:00:00 20.85 20.85 20.84 20.85
2016-01-16 04:00:00 20.85 20.85 20.84 20.85
2016-01-16 05:00:00 20.85 20.85 20.84 20.85
2016-01-16 06:00:00 20.84 20.85 20.84 20.85
x
: object that contains datasymbol
: optional symbol if x
contains multiple symbolsprefer
: optional preferred priceprefer
not specified:"price"
, then "trade"
, then "close"
head(DC)
Price Volume Bid.Price Bid.Size Ask.Price Ask.Size
2016-01-16 00:00:07 NA NA 20.84 198 20.85 684
2016-01-16 00:00:08 NA NA 20.84 198 20.85 683
2016-01-16 00:00:08 NA NA 20.84 198 20.85 682
2016-01-16 00:00:11 NA NA 20.84 198 20.85 683
2016-01-16 00:00:25 NA NA 20.84 198 20.85 684
2016-01-16 00:00:44 20.84 1 20.84 198 20.85 684
dc_bid <- getPrice(DC, prefer = "bid")
head(dc_bid)
Bid.Price
2016-01-16 00:00:07 20.84
2016-01-16 00:00:08 20.84
2016-01-16 00:00:08 20.84
2016-01-16 00:00:11 20.84
2016-01-16 00:00:25 20.84
2016-01-16 00:00:44 20.84
Importing and Managing Financial Data in R