アイルランド証券取引所のウェブサイトから株価を抽出しようとしています。関数を使用している行でエラーが発生していますdatenum()
。
function get_ise_data(equity_name,equity,start_date,end_date)
% Example:
% get_ise_data('CandC',22076,'01-Jan-2010','10-Jan-2010')
% Note:
% This program reads data from the ISE website. It creates a vector of
% trading days, and then requests data for each specific day from the
% website
% Specify the equity name and reference number, start and end dates as in
% the example above.
% C&C corresponds to the reference number 22076 and you can check this on ise.ie. Kerry
% Group and BOI have similar reference numbers.
% The data is saved to a file called "[stock]data.mat". The first
% column is the date in serial number format. You can convert to string
% format using "datestr()" The graph produced is not automatically saved.
% The data is also saved to an excel file by the same name. When viewing in
% Excel we need to change the format of the first column to 'custom'
% and specify format as "hh:mm dd/mm/yy".
% Close the excel file before running the program.
% Convert start and end dates to serial format:
start_date = datenum(start_date, 'dd-mmm-yyyy');
end_date = datenum(end_date, 'dd-mmm-yyyy');
clear final_data
% Work out relevant trading days:
bdates = busdays(start_date, end_date, 'daily');
% The above assumes the same trading days as NYSE - need to modify this for the ISE. See the
% documentation of "busday" to change the default holidays.
itterations=length(bdates);
count=0;
% Loop over each trading day:
for i=1:itterations
[year,month,date]=datevec(bdates(i));
str1='http://www.ise.ie/Prices,-Indices-Stats/EquityMarket-Data/EquityDetails/?equity=';
str2=sprintf('%d&start_day=%d&start_month=%d&start_year=%d',equity,date,month,year);
url=sprintf('%s%s',str1,str2);
raw=urlread(url); % Read in html code from website
exp='<tr?\w+.*?>([\d]+:[\d]+)</\w+.*?>([%\\d/:A-Z\.]+)</\w+.*?>([%\\d/:AZ\.]+)</\w+.*?>([%\-\d/:A-Z\.]+)</\w+.*?>([%\-\d/:AZ\.]+).*?/tr>';
% The following extracts the parts of the html code that match the
% format specified by 'exp':
data = regexp(raw,exp,'tokens','freespacing');
number_of_quotes=length(data);
% Print out current day:
sprintf('Now reading: date: %d, month: %d',date,month)
% A number of quotes are given each day. Loop through these:
for j=1:number_of_quotes
% Determine the serial date number of each quote:
time=data{1,j}(1,1);
hour=regexp(time{1,1},'([\d]+):[\d]+','tokens');
minute=regexp(time{1,1},'[\d]+:([\d]+)','tokens');
hour = str2double(cell2mat(hour{1,1}));
minute = str2double(cell2mat(minute{1,1}));
second=0;
time_serial _number=datenum(year,month,date,hour,minute,second);
price=str2double(cell2mat(data{1,j}(1,3)));
% Save the price and date number to temporary file, while ignoring
% missing data:
if ~isnan(price)
count=count+1;
final_data(count,1)=time_serial_number;
final_data(count,2)=price;
end
end % End of inter-?day loop
end % End of daily loop
str=sprintf('% s_data',equity_name);
% Save data to hard disk:
save(str,'final_data');
xlswrite(str,final_data)
end
私が得るエラーは
??? Error using ==> datenum at 182
DATENUM failed.
Error in ==> get_ise_data at 25
start_date = datenum(start_date, 'dd-mmm-yyyy');
Caused by:
Error using ==> dtstr2dtnummx
Failed on converting date string to date number.
誰かが何か考えを持っていますか?コメントですべてを説明したと思います。
ルース