2

Running

library(quantmod)
getSymbols("^BSESN",src="yahoo")

produces the following error message:

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

This occurs due to the usage of https in the web page. The in-built functionality is not able to download the file necessary for the package since its using secured https connection.

Now there is a need of finding solution for using the https sites in quantmod package like yahoo.

I am using R 3.4.0 latest version and quantmod 0.4-8 I am not able to retrieve data.

Michael Kirchner
  • 869
  • 1
  • 7
  • 17
Sakthi Velan
  • 346
  • 3
  • 13
  • Welcome to Stackoverflow, could you edit your post to include the code you are trying to execute. – Silence Dogood May 17 '17 at 08:12
  • I solved that error. Now I am getting another error. Code: library(quantmod) options(download.file.method="wininet") //I added this line getSymbols("^BSESN",src="yahoo") Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, : cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=^BSESN&a=0&b=01&c=2007&d=4&e=17&f=2017&g=d&q=q&y=0&z=^BSESN&x=.csv' In addition: Warning message: In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, : InternetOpenUrl failed: 'A connection with the server could not be established' – Sakthi Velan May 17 '17 at 08:30
  • These errors because the web-address you are trying to access is down. – Manoj Kumar May 17 '17 at 09:54
  • Sometimes It is down(as you said), Sometimes it is throwing 502 error. The result is inconsistent. – Sakthi Velan May 17 '17 at 13:29

1 Answers1

1

I tried :

library(quantmod)
# Create an object containing the Pfizer ticker symbol
symbol <- "PFE"    
# Use getSymbols to import the data
getSymbols(symbol, src="yahoo", auto.assign=T) 
# because src='google' throws error, yahoo was used, and even that is down

When I tried other source, it worked:

# "quantmod::oanda.currencies" contains a list of currencies provided by Oanda.com
currency_pair <- "GBP/CAD"    
# Load British Pound to Canadian Dollar exchange rate data
getSymbols(currency_pair, src="oanda")
str(GBPCAD)    

It seems there are issues with google and yahoo while we use quantmod pkg.

I will suggest you to use 'Quandl' instead. Plz goto Quandl website, register for free and create API key, and then copy it in below:

# Install Quandl
install.packages("Quandl")
# or from github
install.packages("devtools")
library(devtools)
install_github("quandl/quandl-r")

# Load the Quandl package
library(Quandl)

# use API for full access
Quandl.api_key("xxxxxx")

# Download APPLE stock data
mydata = Quandl::Quandl.datatable("ZACKS/FC", ticker="AAPL")

For HDFC at BSE, you can use:

hdfc = Quandl("BSE/BOM500180")

for more details:

https://www.quandl.com/data/BSE-Bombay-Stock-Exchange?keyword=HDFC
Manoj Kumar
  • 5,273
  • 1
  • 26
  • 33
  • This doesn't answer the question. Check https://github.com/joshuaulrich/quantmod/issues/157 for why Yahoo isn't working and install the development version until the fix hits CRAN. – Michael Kirchner May 18 '17 at 15:34
  • @MichaelKirchner it depends upon the user, if she/he wishes for installing the development version from github or approved package from CRAN. But until the package from CRAN is showing errors, we all have to find an alternative to pursue smoothly what we are working on. Right? I gave one solutions, probably you could have provided other solution instead of down-voting my idea. – Manoj Kumar May 19 '17 at 10:38