Gathering Most Recent Stock Data from Yahoo Finance

2 views (last 30 days)
Hello,
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:
url='https://finance.yahoo.com/d/quotes.csv?s=GOOG&f=og&ignore=.csv';
[temp status]=urlread(strcat(url))
if status
data = textscan(temp, '%f%f', 'delimiter', ',','Headerlines', 0)
else
end
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.
<HTML>
<HEAD>
<TITLE>Document Has Moved</TITLE>
</HEAD>
<BODY BGCOLOR="white" FGCOLOR="black">
<H1>Document Has Moved</H1>
<HR>
<FONT FACE="Helvetica,Arial"><B>
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".
</B></FONT>
<HR>
</BODY>
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.
goog=fopen('GOOG.csv');
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.
Thanks, Carmelo

Accepted Answer

David Ding
David Ding on 27 Apr 2017
Edited: David Ding on 27 Apr 2017
Hi Carmelo,
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:
quote =
'"GOOG",873.600,870.380
'

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!