0

the R package, Quantmod seems to have trouble accessing companies from Google when using the stockSymbols() function.

Here's a list of the companies I'm after from the NYSE, it's just the first 30:

 NYSE
   [1] "A"          "AA"         "AAC"        "AAN"        "AAP"        "AAT"        "AAV"        "AB"         "ABB"       
  [10] "ABBV"       "ABC"        "ABEV"       "ABG"        "ABM"        "ABR"        "ABR-PA"     "ABR-PB"     "ABR-PC"  

Everything works well until it gets to ABR-PA and then returns an error message.

One of the ways I thought I could get around this was by running a Gsub over it to substitute some of the language, and that helped a bit but I'm still missing ~1% of companies from my ~3500 list.

here's the gsub:

NYSE <- gsub("-PK","-K",gsub("-PJ","-J",gsub("-PI","-I",gsub("-PH","-H",gsub("-PG","-G",gsub("-PF","-F",gsub("-PE","-E",gsub("-PD","-D",gsub("-PC","-C",gsub("-PB","-B",gsub("-PA","-A",NYSE)))))))))))

If anyone has tackled this before I'd be keen to hear some thoughts.

DavimusPrime
  • 368
  • 4
  • 17

1 Answers1

0

You can try the following two possible solutions:

getSymbols("ABR-PA", auto.assign=FALSE)

and/or

getSymbols(`ABR-PA`)

Download data for multiple stocks:

NYSE = c("A", "AA", "AAC", "AAN", "AAP", "AAT", "AAV", "AB", "ABB",
        "ABBV", "ABC", "ABEV", "ABG", "ABM", "ABR", "ABR-PA", "ABR-PB",
        "ABR-PC")

data = lapply(NYSE, function(x) {
  getSymbols(x, from="2007-01-01", auto.assign=FALSE)
})

df = do.call(merge, data)
df
AK88
  • 2,946
  • 2
  • 12
  • 31
  • Hmm still comes back with the same error messages, I'm pretty sure it's because on google it's listed as ABR-A whereas the stock symbol comes back as ABR-PA.. – DavimusPrime Jun 06 '17 at 04:59
  • Although you can get around with the following, I couldn't find `ARB-C` on Google: `NYSE = gsub("-P", "-", NYSE)`. Yahoo Finance does have it. Why don't you switch over to YFinance and see? – AK88 Jun 06 '17 at 05:10
  • I always get the following error back from the Yahoo quantmod data: Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, : cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=TCS.NS&a=0&b=01&c=2007&d=5&e=05&f=2017&g=d&q=q&y=0&z=TCS.NS&x=.csv' In addition: Warning message: In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, : cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=TCS.NS&a=0&b=01&c=2007&d=5&e=05&f=2017&g=d&q=q&y=0&z=TCS.NS&x=.csv': HTTP status was '404 Not Found' Also does Yahoo throttle when querying? – DavimusPrime Jun 06 '17 at 05:20
  • 1
    If you update quantmod to version `0.4-9` you can download from Yahoo again and hyphens are no problem. The symbol “ABR-PA” is a special case because yesterday was the first day it was trading :-).(I suggest to always check manually if you run into problems like that ). – hvollmeier Jun 06 '17 at 05:37
  • On my machine I was able to get the data. So maybe updating `quantmod` will solve it. Also see my edit for multiple stocks with `-`. – AK88 Jun 06 '17 at 05:46
  • Okay thanks guys, i'll try and update my Quantmod and see if it works again :) – DavimusPrime Jun 06 '17 at 09:37