0

I am new to coding and to R, I am using R 3.4 and I am trying to retrieve sp 500 prices from yahoo and am getting this error message:

cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=^GSPC&a=0&b=02&c=1996&d=2&e=10&f=2017&g=d&q=q&y=0&z=^GSPC&x=.csv': HTTP status was '502 Connection refused'

Here is the code:

sp500 <- new.env()
getSymbols("^GSPC", env = sp500, src = "yahoo",
     from = as.Date("1996-01-02"), to = as.Date("2017-03-10"))

Thanks.

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
Kirk Lazarus
  • 1
  • 1
  • 2
  • yeah i think their server is under reparation. i thought they had blocked me lol but visiting their page says their engineers are working hard to fix it. It has been down since yesterday, and with no clear horizon on when it will reopen – Rime May 18 '17 at 01:52

2 Answers2

0

I ran into the same issue today as well. I changed the source from yahoo to google and the function call is working correctly.

The issue is not with your code but appears to be the site where the .csv files are accessed at Yahoo. If you copy the URL in the error message you can attempt to connect to the location through your browser. However, the message that you will get is: Our engineers are working quickly to solve the issue.

I tested the same scenario using AAPL as the symbol and compared Yahoo and Google as the source. I also added auto.assign = TRUE to the arguments as the default will be changing in Quantmod from TRUE to FALSE.

getSymbols("AAPL", env = sp500, src = "yahoo", auto.assign = TRUE,
     from = as.Date("1996-01-02"), to = as.Date("2017-03-10"))

Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m,  : 
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=AAPL&a=0&b=02&c=1996&d=2&e=10&f=2017&g=d&q=q&y=0&z=AAPL&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=AAPL&a=0&b=02&c=1996&d=2&e=10&f=2017&g=d&q=q&y=0&z=AAPL&x=.csv': HTTP status was '502 Connection refused'

Changing the source to Google works as expected.

getSymbols("AAPL", env = sp500, src = "google", auto.assign = TRUE,
     from = as.Date("1996-01-02"), to = as.Date("2017-03-10"))

> ls(sp500)
[1] "AAPL"

It does not appear that Google has a .csv for the SP500 that can be used as a replacement for the Yahoo ^GSPC.

Tim Terry
  • 1
  • 3
0

This might be relevant:

https://forums.yahoo.net/t5/Yahoo-Finance-help/Is-Yahoo-Finance-API-broken/td-p/250503/page/3

From someone on that thread who works at YAHOO:

Hi All - This feature was discontinued by the Finance team and they will not be reintroducing that functionality.

The Yahoo Finance Feedback Forum is the place where you can make product suggestions and provide feedback. We’re always trying to improve our products and use your feedback to inform changes. Here’s the url: https://yahoo.uservoice.com/forums/382977

Craig
  • 2,684
  • 27
  • 20