Can getSymbols still work with oanda? - r

I want to get the data of currencies and metals. As I tried some packages, many person suggest quantmod. So I used getSymbols as the following:
getSymbols("USD/EUR",src="oanda")
Error in download.file(paste(oanda.URL, from.date, to.date, "exch=", currency.pair[1], :
cannot open URL 'http://www.oanda.com/convert/fxhistory?lang=en&date1=09%2F28%2F13&date=02%2F09%2F15&date_fmt=us&exch=USD&expr2=EUR&margin_fixed=0&SUBMIT=Get+Table&format=CSV&redirected=1'
In addition: Warning message:
In download.file(paste(oanda.URL, from.date, to.date, "exch=", currency.pair[1], :
cannot open: HTTP status was '404 Not Found'
as I used:
getSymbols("USD/EUR",src="oanda",from="2015-01-01")
I get the same message.
So getSymbols can still work with Oanda?
And another question is where I can find the list of the symbols that the web-service such as Yahoo, Oanda, Google supported? In fact I don't need the stock symbols, I just need the symbols for the future such as corn, gold and the currency.

Oanda changed their URL structure and file format. I fixed this over the weekend. You would need to look on the website of each respective provider in order to find what symbols they support.

Related

Get data from Yahoo! Finance to R

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'
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.
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")

quantmod - getQuote() - '403 Forbidden'

I found an answer to my own question (see below). Still need help.
In the same package, quantmod, there is an option called getSymbol.google.
Nevertheless,
If I use it to get Microsoft value, for example, it works all right
getSymbols.google('MSFT', environment() , src="google", from = (Sys.Date() - 1))
[1] "MSFT"
But, I can´t make it work on a currency pair;
getSymbols.google("GBPUSD", environment() , src="google", from = (Sys.Date() - 1))
Error in download.file(paste(google.URL, "q=", Symbols.name, "&startdate=", :
cannot open URL 'http://finance.google.com/finance/historical?q=GBPUSD&startdate=Nov+02,+2017&enddate=Nov+03,+2017&output=csv'
In addition: Warning message:
In download.file(paste(google.URL, "q=", Symbols.name, "&startdate=", :
cannot open URL 'http://finance.google.com/finance/historical?q=GBPUSD&startdate=Nov+02,+2017&enddate=Nov+03,+2017&output=csv': HTTP status was '400 Bad Request'
Any ideas?
Good morning,
Since the 1ts of November i´m having trouble with the function getQuote from Yahoo. Is a function inside the package "quantmod", which uses yahoo API to request the information.
The description of the function is as follows; Fetch current stock quote(s) from specified source. At present this only handles sourcing quotes from Yahoo Finance, but it will be extended to additional sources over time.
In r, i´m getting the following error; "HTTP status was '403 Forbidden'"
I´ve look on my browser and the error comes from the following error in Yahoo web page "Fetch current stock quote(s) from specified source. At present this only handles sourcing quotes from Yahoo Finance, but it will be extended to additional sources over time."
Does anybody know how to solve ir, or, any alternatives to the function getQuote()
Here is an example from RStudio
getQuote("AAPL")
Error in download.file(paste("https://finance.yahoo.com/d/quotes.csv?s=", :
cannot open URL 'https://finance.yahoo.com/d/quotes.csv?s=AAPL&f=d1t1l1c1p2ohgv'
In addition: Warning message:
In download.file(paste("https://finance.yahoo.com/d/quotes.csv?s=", :
cannot open URL 'https://finance.yahoo.com/d/quotes.csv?s=AAPL&f=d1t1l1c1p2ohgv': HTTP status was '403 Forbidden'
Thanks
seems that yahoo has discontinued this service. Anyone aware of a alternative for yahoo (I'd rather not have to webscrape yahoo for this)
rob
I ran into the same problem... it's kludgey but as a workaround to get the end-of-day value, I have found this to work for now:
Instead of getQuote() to get the Last price (which doesn't seem to work from Yahoo anymore):
underlying<-"AAPL"
quote.last <-getQuote(underlying)$Last
I use "getSymbols" which still works-- throws it into a new data frame, and I pull out the value I want from that:
Hx<-getSymbols(underlying,from=Sys.Date()-1) # allows me to not have to retain the ticker name if I do this across many tickers
quote.last<-as.double(tail(Cl(get(Hx)),1)) # Closing price value from last row of data
rm(list=Hx) # throw away the temporary data frame with quote history
I'm sure the's a more elegant way to do it, but this is what fell out of my brain as a quick workaround that got it done... sadly that doesn't get things like the Bid and Ask that getQuote does.

How to use getReturns with the Yahoo finance API

I have problems with R package getReturns. I have encountered this error since 17th May:
Warning in file(file, "rt") :
cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=AAPL&a=4&b=28&c=2014&d=4&e=27&f=2017&g=w&ignore=.csv': HTTP status was '404 Not Found'
It looks like that ichart API did not run anymore. Can anyone help me with this issue? Does someone know how to fix it? I have encountered the same issue with the quantmod R package.
I have encountered this problem as well. Yahoo! has taken down ichart and the open-source libraries that rely on it are now broken. Yahoo! also has no plans to introduce a replacement. For more information, see this post on Yahoo!'s Forums.
I switched to eodhistoricaldata.com after Yahoo failed, several weeks ago I found good alternative with an API very similar to Yahoo Finance.
Basically, for almost all R scripts I use I just changed this:
URL <- paste0("ichart.finance.yahoo.com/table.csv?s=", symbols[i])
to:
URL <- paste0("eodhistoricaldata.com/api/table.csv?s=", symbols[i])
Then add an API key and it will work in the same way as before. I saved a lot of time for my R scripts on it.
You can follow my an earlier post, which might help you.
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

quantmod `getSymbols.yahoo` uses incorrect date (month number) and creating invalid URL

I am trying to download data of the symbol MACQ by applying the following code:
getSymbols.yahoo("MACQ",.GlobalEnv,from="2010-02-02",to="2016-12-28")
However, I am getting error warning:
Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, :
cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=MACQ&a=1&b=02&c=2010&d=11&e=28&f=2016&g=d&q=q&y=0&z=MACQ&x=.csv'
In addition: Warning message:
In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, :
cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=MACQ&a=1&b=02&c=2010&d=11&e=28&f=2016&g=d&q=q&y=0&z=MACQ&x=.csv': HTTP status was '404 Not Found'
From the message above you can see, that the following url is being used:
'http://ichart.finance.yahoo.com/table.csv?s=MACQ&a=1&b=02&c=2010&d=11&e=28&f=2016&g=d&q=q&y=0&z=MACQ&x=.csv'
If you copy/paste this url into web browser you will really encounter Yahoo! 404 Not Found Problem.
However if you look carefully at the URL, you will notice, that it is using incorrect date reference in the url and thus creating invalid url link. The first "mistake" is that the starting date (i.e. the month) is written in the url as 1&b, but it should have been written as 02&b and also the the end month 11&eshould have been 12&e.
So the link:
http://ichart.finance.yahoo.com/table.csv?s=MACQ&a=1&b=02&c=2010&d=11&e=28&f=2016&g=d&q=q&y=0&z=MACQ&x=.csv
should have looked like this:
http://ichart.finance.yahoo.com/table.csv?s=MACQ&a=02&b=02&c=2010&d=12&e=28&f=2016&g=d&q=q&y=0&z=MACQ&x=.csv
Why is incorrect date used and how to prevent it? This happened to me only when using "MACQ" symbol.
It looks like it's because the MACQ ticker on Yahoo doesn't have much history, and thus the dates are out of scope. Google Finance corroborates this, it appears the stock only has pricing data going back to December 16th, 2016.
The dates in the URL are not incorrect. The months should zero-based, not one-based.
I don't know why this happens for "MACQ", but it probably has something to do with the very short amount of history available. The oldest observation on the historical data page for MACQ is 2016-12-23. If you download all the data for "MACQ", you only get 2017-01-03 through 2017-01-05.
Also note that you should not call getSymbols.yahoo directly (as it says in ?getSymbols.yahoo).

Using R package BerkeleyEarth

I'm working for the first time with the R package BerkeleyEarth, and attempting to use its convenience functions to access the BEST data. I think maybe it's just a problem with their servers (a matter I've separately addressed to the package's maintainer) but I wanted to know if it's instead something silly I'm doing.
To reproduce my fault
library(BerkeleyEarth)
downloadBerkeley()
which provides the following error message
trying URL 'http://download.berkeleyearth.org/downloads/TAVG/LATEST%20-%20Non-seasonal%20_%20Quality%20Controlled.zip'
Error in download.file(urls$Url[thisUrl], destfile = file.path(destDir, :
cannot open URL 'http://download.berkeleyearth.org/downloads/TAVG/LATEST%20-%20Non-seasonal%20_%20Quality%20Controlled.zip'
In addition: Warning message:
In download.file(urls$Url[thisUrl], destfile = file.path(destDir, :
InternetOpenUrl failed: 'A connection with the server could not be established'
Has anyone had a better experience using this package?
The error message is pointing to a different URL than one should get judging what URLs are listed at http://berkeleyearth.org/data/ that point to the zip formatted files. There are another set of .nc files that appear to be more recent. I would replace the entries in the BerkeleyUrls dataframe with the ones that match your analysis strategy:
This is the current URL that should be in position 1,1:
http://berkeleyearth.lbl.gov/downloads/TAVG/LATEST%20-%20Non-seasonal%20_%20Quality%20Controlled.zip
And this is the one that is in the package dataframe:
> BerkeleyUrls[1,1]
[1] "http://download.berkeleyearth.org/downloads/TAVG/LATEST%20-%20Non-seasonal%20_%20Quality%20Controlled.zip"
I suppose you could try:
BerkeleyUrls[, 1] <- sub( "download\\.berkeleyearth\\.org", "berkeleyearth.lbl.gov", BerkeleyUrls[, 1])

Resources