Is it possible to run this loop?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi guys,
I am trying to run a nested loop that will pull data from Yahoo Finance and will export some information into a column.
Here is the code I have so far:
%Open File
fid=fopen('C:\Users\Laurentiu Galan\Desktop\pca1.csv');
C = textscan(fid, '%s %s %s %*s %*s %*s %*s', 'delimiter', ',', ...
'HeaderLines', '1');
fclose(fid);
%Strcat Identifier
tickername=C{1};
year=C{2};
month=C{3};
%Get Size of Loop for filepath
D=size(tickername);
numval=D(1,1);
%Calculate Loop to download tickers
for i=1:numval
url_string = strcat('http://ichart.finance.yahoo.com/table.csv?s=', tickername{i}, '&d=1', '&e=', month{i}, '&f=', year{i}, '&g=m&a=1', '&b=', month{i}, '&c=', year{i}, '&ignore=.csv')
end
%Create Loop for url_string and buffers by opening connection and
%retrieving data into a buffer
%for j=1:numval
buffer = java.io.BufferedReader(...
java.io.InputStreamReader(...
openStream(...
java.net.URL({j}))));
% Begin with 2nd line (exclude header)
ptr = 1;
while 1
% Read line
buff_line = char(readLine(buffer));
% Break if this is the end
if length(buff_line)<3, break; end
% Find comma delimiter locations
commas = find(buff_line== ',');
% Extract high, low, open, close, etc. from string
adj_close = str2num( buff_line(commas(6)+1:end) )
ptr = ptr + 1;
end
%end
How Do I finish this code to simply give me the 'adj_close' for each corresponding ticker in the file? Please Note, I don't want multiple dates, just the price data for the first of the month for each tickername, month and year.
Please note, there is a header every time I read the lines, so the header must be excluded somehow.
I really appreciate any help with this. I've fairly new at Matlab and would appreciate any advice or additional guidance...
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Money.Net에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!