Atrad
Atrad

Reputation: 85

quantmod ... unable to get OHLCV symbol data for current day

I am not able to get OHLCV data from yahoo for current day using Quantmod getSymbols() call. The data exists on yahoo and can also see today's OHLCV data in my charting platform. As workaround I got today's EOD quote from yahoo using getQuote(..) call. But when I tried to append this to the downloaded symbol data via rbind, the data object gets populated with NULLs.

I appreciate any suggestions on either how to append the today's quote to the downloaded historic symbol data or any R API's I can call after market hours to get symbol EOD (OHLCV data) including for today. Thanks.

library(quantmod)
library(blotter) 
library(PerformanceAnalytics)

getSymbols("SPY")
spy.quote = getQuote("SPY", what = yahooQuote.EOD)

> tail(SPY, n=3)
           SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
2012-10-25   142.02   142.28  140.57    141.43  134457400       141.43
2012-10-26   141.30   141.84  140.39    141.35  146023500       141.35
2012-10-31   141.85   142.03  140.68    141.35  103341300       141.35

> spy.quote
             Trade Time   Open   High    Low  Close    Volume
SPY 2012-11-01 04:00:00 141.65 143.01 141.52 142.83 100990760

> SPY = rbind(SPY, spy.quote)
> tail(SPY, n=3)
          SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
          NULL     NULL     NULL    NULL      NULL       NULL               
          NULL     NULL     NULL    NULL      NULL       NULL        
spy.quote NULL     NULL     NULL    NULL      NULL       NULL  

Upvotes: 3

Views: 1043

Answers (1)

GSee
GSee

Reputation: 49810

You need to convert the quote data from a data.frame to an xts object and add a column for Adjusted price. Then you can rbind.

getSymbols("SPY", src='yahoo', to='2012-10-31')
spy.quote = getQuote("SPY", what = yahooQuote.EOD)

# convert to xts
xts.quote <- xts(spy.quote[, -1], as.Date(spy.quote[, 1])) # use Date for indexClass
xts.quote$Adjusted <- xts.quote[, 'Close'] # add an Adjusted column

tail(rbind(SPY, xts.quote), 3)
           SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
2012-10-26   141.30   141.84  140.39    141.35  146023500       141.35
2012-10-31   141.85   142.03  140.68    141.35  103341300       141.35
2012-11-01   141.65   143.01  141.52    142.83  100995568       142.83

Upvotes: 3

Related Questions