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

286 views Asked by At

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.

2

There are 2 answers

3
Cameron Pfiffer On

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.

0
Joshua Ulrich On

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