0

I want to get OHLC data from google finance from London Stock Exchange. I've tried using:

> require(quantmod)
> getSymbols("LON:DRTY", src="google")
[1] "LON:DRTY"
> head(LON:DRTY)
Error in head(LON:DRTY) : object 'LON' not found

getSymbols seems to have returned the data, but I cannot access it. How do I actually get the data from the returned object?

Actually, I want to download data from Japan. For example:"TYO:2501" (https://www.google.com/finance?q=TYO%3A2501&ei=2aC6VOHcKsX1wAPa3YCoCg). However, getSymbols can't find it under tickers like "TYO:2501", "2501", "TYO%3A2501". I get '404 Not Found' or '400 Bad Request'.

> getSymbols("TYO:2502", from="2014-01-01", to="2014-05-03", src="google")
Yi Sha
  • 81
  • 7
  • 4
    To the down-voters: if you run the code, you'll see that data are actually returned. The question is how to access the oddly-named object. – Joshua Ulrich Jan 05 '15 at 13:45
  • http://stackoverflow.com/questions/14760622/renaming-an-object, http://stackoverflow.com/questions/19336499/how-to-handle-hyphens-in-yahoo-finance-tickers-in-quantmod – GSee Jan 05 '15 at 16:29
  • Regarding your edit, google doesn't provide the data you're looking for in the same way that it provides other data. Look at [this link for SPY data](https://www.google.com/finance/historical?q=NYSEARCA%3ASPY&ei=Ary7VOHrJY6mqwGhjYDwCA). See the link on the right side of the page to download to spreadsheet? There is no such link on the right hand side of [the page you're looking at](https://www.google.com/finance/historical?q=TYO%3A2501&ei=6ru7VPH0PI6mqwGhjYDwCA) – GSee Jan 18 '15 at 14:00

1 Answers1

2

In this case getSymbols does not return a syntactically valid name. : is a binary operator in R, used to create sequences of numbers. So when you type head(LON:DRTY) R is looking for an object named LON and an object named DRTY in order to create a sequence. For example:

> LON <- 1
> DRTY <- 10
> head(LON:DRTY)
[1] 1 2 3 4 5 6

I will fix this in a future release, but you can use one of these work-arounds in the meantime:

> require(quantmod)
> getSymbols("LON:DRTY",src="google")
[1] "LON:DRTY"
> # use backticks to reference the object
> head(`LON:DRTY`)
           LON:DRTY.Open LON:DRTY.High LON:DRTY.Low LON:DRTY.Close LON:DRTY.Volume
2012-08-01          0.43          0.45         0.41           0.44          410093
2012-08-02         41.25         42.75        40.00          41.50          751816
2012-08-03         41.00         44.00        41.00          42.75          582187
2012-08-06         42.00         44.41        42.00          42.50          370042
2012-08-07         42.00         44.00        40.75          42.00         1366845
2012-08-08         42.00         42.50        42.00          42.25          437467
> # manually assign the object to a "valid" name
> LON.DRTY <- getSymbols("LON:DRTY",src="google",auto.assign=FALSE)
> head(LON.DRTY)
           LON:DRTY.Open LON:DRTY.High LON:DRTY.Low LON:DRTY.Close LON:DRTY.Volume
2012-08-01          0.43          0.45         0.41           0.44          410093
2012-08-02         41.25         42.75        40.00          41.50          751816
2012-08-03         41.00         44.00        41.00          42.75          582187
2012-08-06         42.00         44.41        42.00          42.50          370042
2012-08-07         42.00         44.00        40.75          42.00         1366845
2012-08-08         42.00         42.50        42.00          42.25          437467
> # use setSymbolLookup to specify the name
> setSymbolLookup(LON.DRTY=list(name="LON:DRTY",src="google"))
> getSymbols("LON.DRTY")
[1] "LON.DRTY"
> head(LON.DRTY)
           LON:DRTY.Open LON:DRTY.High LON:DRTY.Low LON:DRTY.Close LON:DRTY.Volume
2012-08-01          0.43          0.45         0.41           0.44          410093
2012-08-02         41.25         42.75        40.00          41.50          751816
2012-08-03         41.00         44.00        41.00          42.75          582187
2012-08-06         42.00         44.41        42.00          42.50          370042
2012-08-07         42.00         44.00        40.75          42.00         1366845
2012-08-08         42.00         42.50        42.00          42.25          437467
Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418