MATLAB: Is execution time so slow when indexing large FINTS objects when Time-of-Day Data Is Present in Financial Toolbox 3.2 (R2007a)

Financial Toolbox

When I execute the following code (please load attached 'f1.mat' and 'aspread.mat'):
load f1
load aspread
Dates_times=datestr(aspread.dates + aspread.times,'dd-mmm-yyyy HH:MM');
tic;f_new=f1(Dates_times);toc;
Indexing this financial time series object takes a very long time using the DATESTR function. This takes more than 2 minutes for 121000 dates and took 21 minutes for 129000 elements.

Best Answer

It is expected that Financial Time Series objects suffer from a performance hit when dealing with date strings that contain hours and minutes.
Suppose we have a DATENUM element with time information as well:
now
returns:
ans =
7.331974545514584e+005
You are dealing with floating point numbers that need to be located in a vector
Furthermore, you are not dealing with anything on the scale of seconds or milliseconds, so further processing on the date string is needed (i.e. truncation of the date).
Truncation of the date number results in roundoff errors, and roundoff errors lead to improper conversions to datestrings (things could get rounded to the next second or even hour).
Thus, a lot of ‘error checking’ needs to go into subreferencing the object with SUBSREF when something like the following is done: fintsObj(‘dd-mmm-yyy hh:mm’).
Because of all this error checking when it comes to dates with times, it is not surprising that a slowdown occurs when you are trying to reference 121000 or 129000 date strings.
One possible workaround is to execute the following:
[dates,ind]=intersect(f1.dates+f1.times,aspread.dates+aspread.times);
tic;f_new=f1(ind);toc;
This is much faster than indexing date strings directly with DATESTR.