0

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.

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418
Pat Amat
  • 23
  • 7
  • 1
    It looks like you can report issues with `quantmod` here: https://github.com/joshuaulrich/quantmod/issues; you might consider posting your example there to directly get in touch with the package author. – Kevin Ushey Jan 06 '17 at 17:21

2 Answers2

1

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.

  • Yes, but the thing is, that I want to download daily quotes of many stocks from to specific date. I created a loop for it. However if I encounter a stock, for which data cannot be downloaded I am returned an error and entire loop is stopped. In order to prevent this, I am checking whether urls are available by applying url.exists() For this I am creating the same structure of url as in getSymbols does. MACQ is able to bypass url.exists, however problem is encountered in getSymbols because for some reason with this stock, the structure of url changes. – Pat Amat Jan 06 '17 at 17:57
  • @PatAmat: See the answers to [this question](http://stackoverflow.com/q/27892150/271616). The tl;dr is: use `try` to capture errors and skip tickers without interrupting the loop. – Joshua Ulrich Jan 06 '17 at 18:05
  • Thank you very much. This is what I am looking for right now! – Pat Amat Jan 06 '17 at 18:10
0

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

Joshua Ulrich
  • 173,410
  • 32
  • 338
  • 418