0

I am trying to get data from Yahoo! Finance to R

I've installed quantmod like that:

install.packages("quantmod", repos="http://R-Forge.R-project.org")

But when I try this:

getQuote("QQQQ;SPY", what=yahooQF("Last Trade (Price Only)"))

I see:

Error in download.file(paste("http://finance.yahoo.com/d/quotes.csv?
s=",  : 
cannot open URL 'http://finance.yahoo.com/d/quotes.csv?
s=QQQQ+SPY&f=d1t1l1'
In addition: Warning message:
In download.file(paste("http://finance.yahoo.com/d/quotes.csv?s=",  :
URL 'http://download.finance.yahoo.com/d/quotes.csv?
s=QQQQ+SPY&f=d1t1l1': status was 'Couldn't resolve host name'
Oktu
  • 187
  • 1
  • 4
  • 10

2 Answers2

1

To answer the specific question asked:

getSymbols("QQQ;SPY", from="1997-12-31", src='yahoo')  

works just fine - you get two xts series, QQQ and SPY (note that QQQQ is "dead" and replaced with QQQ), with 6 columns Open, High, Low, Close, Volume, Adjusted.
It looks like you only want the close? If so, you can get just that series with

Cl(QQQ)

If you don't like auto-assignment, you can use

qqq.data <- getSymbols("QQQ", auto.assign=FALSE, from="1997-12-31", src='yahoo')

to assign the downloaded data to a variable of your choice. Note that most people would probably be interested in the adjusted price instead, if so, you can select it with

Ad(QQQ)

Finally, indeed, as pointed out, google finance no longer provides data through its API.

tchevrier
  • 1,041
  • 7
  • 16
0

getSymbols("AAPL",src="google") has been deprecated.

Error: ‘getSymbols.google’ is defunct. Google Finance stopped providing data in March, 2018. You could try setting src = "yahoo" instead. See help("Defunct") and help("quantmod-defunct")

Jens Habegger
  • 5,266
  • 41
  • 57
  • 1
    Thanks, Andrew. This is useful information. Although, it doesn't answer the OP's question and would have been better suited as a comment. – Graeme Walsh Aug 22 '18 at 14:14