Capturing Intraday data, Backup plan
In the Capturing Intraday data post, I outlined steps to setup your own process to capture Intraday data. But what do you do if you missed some data points due for example internet being down or due to power outage your server was re-started. To fill up the gaps in the Intraday data, you could get up to 10 day historical Intraday data from Google finance.
I created a wrapper function for Google finance, getSymbol.intraday.google() function in data.r at github, to download historical Intrday quotes. For example,
############################################################################## # Load Systematic Investor Toolbox (SIT) # https://systematicinvestor.wordpress.com/systematic-investor-toolbox/ ############################################################################### setInternet2(TRUE) con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb')) source(con) close(con) #***************************************************************** # Load Intraday data #****************************************************************** data = getSymbol.intraday.google('GOOG', 'NASDAQ', 60, '5d') last(data, 10) plota(data, type='candle', main='Google Intraday prices')
> last(data, 10) Open High Low Close Volume 2014-03-28 15:52:00 1119.10 1119.61 1119.10 1119.610 4431 2014-03-28 15:53:00 1119.30 1119.30 1118.75 1118.805 3954 2014-03-28 15:54:00 1119.31 1119.45 1119.18 1119.340 5702 2014-03-28 15:55:00 1119.17 1119.40 1119.00 1119.340 8907 2014-03-28 15:56:00 1119.19 1119.35 1119.18 1119.190 11882 2014-03-28 15:57:00 1119.30 1119.30 1119.02 1119.270 6298 2014-03-28 15:58:00 1119.25 1119.35 1119.15 1119.265 10542 2014-03-28 15:59:00 1119.38 1119.49 1118.82 1119.250 29496 2014-03-28 16:00:00 1120.15 1120.15 1119.15 1119.380 71518 2014-03-28 16:01:00 1120.15 1120.15 1120.15 1120.150 0
So if your Intraday capture process failed, you can rely on Google fiance data to fill up the gaps.
Categories: R
Hello, I just wonder if you can modify it a bit so that I can apply it to the Chinese stock market. I have tried this function but the time zone is not really correct. Many thanks
Hi,
I just reviewed your code and wanted to inform you about a minor mistake in the getSymbol.intraday.google() function. For some reason the prices obtained via http://www.google.com/finance/getprices come with the close price first. You would have to switch them to get them in common OHLC order.
That would mean something like:
# #
# switch 2nd column with 5th column since google places close price first
# #
out=as.data.frame(out)
out=out[,c(1,5,3,4,2,6)]
setnames(out, c(‘Date’,’Open’,’High’,’Low’,’Close’,’Volume’))
# #
Since the object type has been changed to a dataframe I guess you would have to adapt your make.xts() as well or just do:
out=xts(out[,c(2,3,4,5,6)],date)
Best regards,
Ole Fass
_______
Quantessence
Great Article!