Error using getSymbols function in R (https)
Running
library(quantmod)
getSymbols("^BSESN",src="yahoo")
the following error message is displayed:
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 is due to the use of https on the web page. The built-in functionality cannot download the file required for the package because it uses a secure https connection.
Now we need to find a solution for using https sites in quantmod package, for example yahoo.
I am using the latest version 3.4.0 and quantmod 0.4-8 I cannot get the data.
+1
source to share
1 answer
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 another 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)
There seems to be problems with google and yahoo while we are using quantmod pkg.
I suggest you use "Quandl" instead. Plz goto Quandl, sign up for free and create an API key then copy it 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 on BSE you can use:
hdfc = Quandl("BSE/BOM500180")
for more details:
https://www.quandl.com/data/BSE-Bombay-Stock-Exchange?keyword=HDFC
+1
source to share