Is it possible to use the Yahoo Query Language to download historical financial data?
Question: I've used the Yahoo Finance site to download historical data, using queries
like this:

    
    
    http://ichart.finance.yahoo.com/table.csv?s=AAPL&c=1962
    

and the accompanying Python code:

    
    
    import urllib.request
    with open("data.csv", "wb") as w:
        url = "http://ichart.finance.yahoo.com/table.csv?s=AAPL&c=1962"
        r = urllib.request.urlopen(url).read()
        w.write(r)
    

I've also used the Yahoo Query Language to download pseudo-realtime data (i.e.
data delayed by a few minutes) with queries like this:

    
    
    http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22AAPL%22)&env=store://datatables.org/alltableswithkeys
    

However, I can't find documentation on how to download historical data (as
shown in the first query) using the YQL (as shown in the second query). I'd
like to do this before the tables returned by the YQL contain much more data
than simply opening/closing prices, volume, etc.

Is there a way to download historical data using the YQL in such a way that it
contains the same depth of detail as the pseudo-realtime data?


Answer: Unfortunately, the YQL table `yahoo.finance.historicaldata` contains the same
fields as the CSV files, specifically the opening price, closing price, high,
low, volume, etc. To download this data using YQL, this is an example of the
proper query:

    
    
    select * from yahoo.finance.historicaldata where symbol = "IBM" and startDate = "2012-01-01" and endDate = "2012-01-11"
    

