Gathering Most Recent Stock Data from Yahoo Finance
6 views (last 30 days)
I am working on a program that will retrieve data the most recent data from yahoo fiance (without the DataFeed toolbox), to be processed in a separate program. I found a helpful webpage which details the necessary URL address to download data from.
So for a ticker, say GOOG, I can construct the appropriate URL and put it into my seachbar and the resulting .csv file is downloaded to my computer. I am now trying to implement this in matlab using the following:
data = textscan(temp, '%f%f', 'delimiter', ',','Headerlines', 0)
In theory, this should return data with the requested information (in this case, the open price (o) and days low (g)). When running the program I get the following from temp.
<TITLE>Document Has Moved</TITLE>
<BODY BGCOLOR="white" FGCOLOR="black">
<H1>Document Has Moved</H1>
Description: The document you requested has moved to a new location. The new location is "http://download.finance.yahoo.com/d/quotes.csv?s=GOOG&f=sog&ignore=.csv".
Although it says there is a new location for the document, I can still use the old URL to download directly by copying and pasting it into the seachbar.
Additionally, when downloaded that hard way, I can save the data and read it as normal. For instance, after downloading the .csv by copying and pasting the URL into my seachbar, the following code works to extract the data to matlab.
data = textscan(goog, '%f%f', 'delimiter', ',','Headerlines', 0)
Any help as to why matlab will not let me access the data would be tremendously helpful.
David Ding on 27 Apr 2017
Edited: David Ding on 27 Apr 2017
Recently, Yahoo made a few changes to the protocol of their Finance APIs.
Please try adding the "UserAgent" name-value parameter in your call to the "urlread" function, as well as use the suggest URL, as follows :
>> url = 'http://download.finance.yahoo.com/d/quotes.csv?s=GOOG&f=sog&ignore=.csv';
>> quote = urlread(url, 'UserAgent', 'matlab')
I tried this, and I got an output: