I have an xls sheet called Tickers (matrix 1 column 500 rows) with yahoo tickers. I want matlab to download the historical data for last 5 years for each stock ticker into a separate xls spreadsheet and save it in a given directory with title of the sheet = ticker. So that means i want a code that will create and save 500 tickers worth of data in 500 separate spreadhseets :) can anyone help or direct?
Asked
Active
Viewed 2,617 times
1
-
Please give an example of the data format (first 4 lines of the file) – abcde123483 Nov 22 '11 at 17:47
-
Date Open High Low Close Volume Adj Close – Noob_1 Nov 22 '11 at 17:57
-
11/21/2011 28.17 28.2 28 28.05 8800 28.05 – Noob_1 Nov 22 '11 at 17:58
1 Answers
0
If you have the Datafeed Toolbox, you can use it to download historical financial data from Yahoo.
Here is an example using only three tickers, but could be easily changed to read the values from file and applied to all 500 tickers you have:
endDate = date; %# today
startDate = datestr(addtodate(datenum(endDate),-1,'year')); %# last year
tickers = {'GOOG' 'IBM' 'AAPL'};
headers = {'Date' 'Open' 'High' 'Low' 'Close' 'Volume' 'Adj Close'};
y = yahoo;
for i=1:numel(tickers)
%# fetch daily data
data = fetch(y, tickers{i}, startDate, endDate, 'd');
%# format dates, and add header row
A = [headers; cellstr(datestr(data(:,1))) num2cell(data(:,2:end))];
%# write to XLS file
xlswrite([tickers{i} '.xls'], A);
end
close(y);
An example of the data you get:
>> A
A =
'Date' 'Open' 'High' 'Low' 'Close' 'Volume' 'Adj Close'
'21-Nov-2011' [ 370.4] [371.68] [365.91] [369.01] [15999300] [ 369.01]
'18-Nov-2011' [378.92] [379.99] [374.88] [374.94] [13283500] [ 374.94]
'17-Nov-2011' [383.98] [384.58] [ 375.5] [377.41] [17139300] [ 377.41]
'16-Nov-2011' [389.25] [391.14] [384.32] [384.77] [12449900] [ 384.77]
'15-Nov-2011' [ 380.8] [ 389.5] [379.45] [388.83] [15386100] [ 388.83]
...

Amro
- 123,847
- 25
- 243
- 454
-
if you don't have access to the toolbox, you would have to manually fetch the data using the Yahoo CSV API (see this [previous answer](http://stackoverflow.com/questions/6717218/yahoo-fetching-currency-in-matlab/6718234#6718234)) – Amro Nov 22 '11 at 18:41