Error in getSymbols function usage in R(https) [cl

2020-07-26 18:22发布

问题:

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.

回答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