Home > R > Capturing Intraday data, Backup plan

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

plot1

So if your Intraday capture process failed, you can rely on Google fiance data to fill up the gaps.

Categories: R
  1. skye
    August 20, 2014 at 7:10 am

    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

  2. September 1, 2014 at 3:28 pm

    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

  3. Mohamed Amr Elgeneidy
    September 25, 2016 at 12:57 pm

    Great Article!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: