[R-SIG-Finance] error catching in getSymbols

Joshua Ulrich josh.m.ulrich at gmail.com
Wed Apr 4 15:04:55 CEST 2012


On Wed, Apr 4, 2012 at 12:52 AM, benn fine <bennfine at gmail.com> wrote:
> I've googled and found a similar question at
> http://stackoverflow.com/questions/8502512/quantmod-overriding-the-warning-message but
> no answer.........
>
There is an answer to that question.  Wrap your getSymbols call in try().

> When I loop over several stocks using getSymbols, yahoo will occasionally
> barf as if I have asked it for too many quotes.
> Is there a workaround for this? Using Sys.sleep doesn't seem to help:
>
It doesn't fail because you asked for too many quotes.  It tells you
exactly why it fails:
"cannot open: HTTP status was '404 Not Found'"
The Yahoo server can't find the page you requested.  I.e. historical
data doesn't exist for that symbol.

> sdvals=1:100
> for(i in 1:100)  {
> Sys.sleep(2)
> cat("Getting Data for Stock ",nas100[i,1],"\n")
> foo=getSymbols(nas100[i,2],auto.assign=FALSE)
> rfoo=monthlyReturn(foo)
> sdvals[i]=sqrt(var(rfoo))
> }
>
> Getting Data for Stock  Activision
> Getting Data for Stock  Adobe
> Getting Data for Stock  Akamai
> Getting Data for Stock  Alexion
> Getting Data for Stock  Altera
> Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,
> :
>  cannot open URL '
> http://chart.yahoo.com/table.csv?s=ALTR&a=0&b=01&c=2007&d=3&e=04&f=2012&g=d&q=q&y=0&z=ALTR&x=.csv
> '
> In addition: Warning message:
> In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  :
>  cannot open: HTTP status was '404 Not Found'
>
> Thanks!
>

--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com

R/Finance 2012: Applied Finance with R
www.RinFinance.com



More information about the R-SIG-Finance mailing list